New York has become the sixth and most populous US state to allow same-sex marriage.
The Republican-controlled state senate voted 33-29 for a bill that had earlier been approved by the lower house, which has a Democratic majority.
New York Governor Andrew Cuomo quickly signed the bill into law. Gay weddings are expected to start within 30 days.
It has become a contentious social issue ahead of next year's presidential and congressional elections.
"New York has finally torn down the barrier that prevented same-sex couples from exercising the freedom to marry and from receiving the fundamental protections that so many couples and families take for granted," Mr Cuomo said in a statement.
He kept his promise to sign the bill as soon as he received it after the Senate vote - rather than wait the usual 10 days.
Gay rights activists said the approval of the bill was a key victory for them, in what is seen as the birthplace of the US gay rights movement.
"It's about time. I want to get married. I want the same rights as anyone else," 36-year-old student Caroline Jaeger told Reuters news agency.
But New York's Catholic bishops said they were "deeply disappointed and troubled" by the passage of the bill, Reuters news agency reports.
Just four Republicans voted for the bill, but it was enough to make the New York senate the first Republican-controlled legislative chamber in the country to vote in favour of same-sex marriage.
New York now joins Connecticut, Iowa, Massachusetts, New Hampshire, Vermont and also the District of Columbia, all of which allow same-sex marriages.