New York Gov. Andrew Cuomo signed a bill to legalize same-sex marriage late Friday, shortly after the state Senate voted on the measure, delivering a significant victory to the gay rights movement and making New York the largest state to permit such unions.

Given the state’s population, the vote essentially doubles the number of Americans who can gain access to same-sex marriage licenses, which previously have been available in five states and the District of Columbia.

The measure, a priority of Cuomo (D), had passed the Democratic-controlled State Assembly last week but stalled in the Republican-controlled Senate.

The 33 to 29 vote came after days of tense negotiations, extending the state’s legislative session about a week after its scheduled end and drawing crowds of protesters on both sides of the issue into the Capitol daily. Each morning brought rumors that the issue would finally come up for a vote; each night, the Senate adjourned without a resolution on the issue.

Without a clear indication of how the vote would go, senators finally gathered late Friday after party leaders reached agreement on language that strengthened legal protections for religious institutions that oppose same-sex marriage.

Cuomo signed the bill shortly before midnight Friday, and gay couples will be able to wed within 30 days.

“New York has finally torn down the barrier that has 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,” Cuomo said in a statement. “With the world watching, the Legislature, by a bipartisan vote, has said that all New Yorkers are equal under the law.”

The decision was welcomed by gay rights groups, who had been hungry for a win after similar measures failed this year in Maryland and Rhode Island.

The bill’s passage also was viewed as a milestone nationally because it was the first time a GOP-controlled chamber has approved gay marriage.

Several wealthy Republicans backed the effort, and it was ultimately Republican senators who cast the tiebreaking votes. Four Republicans joined with the vast majority of the Senate’s Democrats to pass the bill. The Republicans hold a one-member majority in the chamber.

“With the freedom to marry in New York, the nationwide majority for marriage will swell, as even more people get to see why marriage matters to same-sex couples, that gay couples, like non-gay, treasure the chance to affirm and strengthen their commitment, and that ending marriage discrimination helps families and hurts no one,” said Evan Wolfson, executive director of the pro-gay marriage group Freedom to Marry, in a statement.

Opponents had poured millions of dollars into the fight and said there would be swift and direct retribution against the lawmakers who voted for this bill. They pledged $1 million toward defeating Republicans who voted for it and backing Democrats who voted against it.

“Marriage loses 33-29 in New York. Sad day for the state and the country. But the fight has just begun,” came a tweet from the National Organization for Marriage, a group that opposes same-sex marriage.

The decision came a day after President Obama appeared at a Manhattan fundraiser before an audience of gay donors. Obama campaigned as an opponent of gay marriage but more recently has said his views on the issue are “evolving.”

The president did not indicate any change of heart, despite the calls of “Marriage!” and “Do you support it?” from the audience. All week, activists have been calling on Obama to “evolve already,” noting that his position puts him to the right of the Republicans who supported same-sex marriage in New York.

At the event, he listed his accomplishments on gay rights and said, “I believe that gay couples deserve the same legal rights as every other couple in this country.”

The vote caps a mixed year for gay marriage in state legislatures. New York was the only state to approve same-sex marriages. Three states — Delaware, Hawaii and Illinois — voted to allow gay couples to enter into civil unions, which afford many of the same benefits as marriage. Although gay groups consider civil unions a positive step, they say it falls short of the true legal and symbolic equality that the term “marriage” carries with it.

In Minnesota, lawmakers decided to place a measure on the 2012 ballot asking voters to define marriage as exclusively between a man and a woman. Voters have supported such language in all 31 states that have put that question on the ballot. However, with public opinion shifting, according to several recent polls, and with Minnesota’s liberal tilt, advocates hope it will be their first opportunity to defeat such a ballot initiative.

A similar initiative passed in California in 2008. However, in a major victory for the pro-gay-marriage movement, a federal judge last year overturned that law and called into question the constitutionality of such ballot measures. The issue is widely expected to be settled by the U.S. Supreme Court.

A Washington Post poll in March showed that a slim majority of Americans support gay marriage, a dramatic rise from just five years ago.

In New York, a series of actors, singers, professional athletes and politicians, including New York City Mayor Michael R. Bloomberg (I) and former president Bill Clinton had urged the legislature to pass the bill.

More than 50,000 viewers tuned in to watch the Senate debate late Friday, which was streamed live online. Because the bill appeared to be a single vote short of passage in the Republican-led chamber earlier in the day, speculation was rampant about the bill’s chances until the last minute.

As the discussion opened up, a formerly undecided Republican — Sen. Stephen Saland of Poughkeepsie — stood first to announce that after an “intellectual and emotional journey” he had decided to back the legislation, ensuring the bill’s passage. He was joined a short while later by GOP Sen. Mark Grisanti. And it was a Democrat, Sen. Ruben Diaz Jr., who spoke most passionately against same-sex marriage. Diaz noted that the same bill failed two years ago when both chambers were controlled by Democrats.

“Listen very carefully and know the following: The New York gay community and their supporters are not only getting their marriage bill approved, but most importantly they are making the Republican Party do what the democrats failed to do when they were in the majority,” said Diaz, the lone Democratic senator who voted no.

Foes of same-sex marriage — including several religious groups and New York Archbishop Timothy Dolan — had hoped for an outcome similar to the one in Maryland , where lawmakers decided not to bring the measure up for a vote after a Democratic legislator who was lobbied by African American churches announced at the 11th hour that she would not back the bill.

New York and Maryland highlight recent fissures that have emerged in the debate over gay marriage. As more and more Republicans warm up to the idea, it has been Democrats — most visibly, those who hail from black and Latino Christian communities — who have stood in the way.