Albany, New York (CNN) -- New York's Republican-controlled legislature cleared the way Friday to legalize same-sex marriage with a 33-to-29 vote, sending the bill to the governor's desk for his approval.

The vote came after days of delays that saw last-minute lobbying on all sides, passing by a slim margin with Republican support -- the first time a state legislature with a Republican majority has approved such a bill.

Once Gov. Andrew Cuomo, who proposed the bill, signs it, same-sex couples will be able to marry 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, a Democrat, said in a written statement shortly after the vote.

A vote on the measure, which the state assembly passed June 15, has been stalled in the Senate until Friday. But it turned a corner late Friday, according to Senate Majority Leader Dean Skelos, after lawmakers agreed on an amendment to protect religious groups from litigation that had been pushed by Republicans.

Earlier in the day, the Assembly passed a new version of the bill that included the amendment about religious institutions.

Cuomo said it would grant same-sex couples equal rights to marry "as well as hundreds of rights, benefits and protections that are currently limited to married couples of the opposite sex."

Currently, five states -- Massachusetts, Connecticut, Iowa, Vermont and New Hampshire -- and the District of Columbia grant same-sex marriage licenses.

Activists on both sides of the issue gathered in the state capitol, Albany. They chanted opposing slogans -- petitioning for either "marriage equality" or yelling "one man, one woman" in defense of the institution's traditional definition -- though they could also be seen occasionally mingling and even singing religious songs together.

Republicans, led by Skelos, had expressed concerns over the "unintended consequences" of a bill that redefines the legal parameters of marriage. The measure needed three Republicans' votes to pass the bill, which had the support of 31 Senators -- just one short of the number required for passage -- earlier this week.

New York Mayor Michael Bloomberg, who courted Republican state senators to approve the bill, called the vote a "historic triumph for equality and freedom."

"In recent weeks, I have had many conversations with our State Senators. I emphasized that not only is marriage equality consistent with bedrock American principles, but it is also consistent with bedrock Republican Party principles of liberty and freedom -- and the Republicans who stood up today for those principles will long be remembered for their courage, foresight, and wisdom. In fact, 10 or 20 or 30 years from now, I believe they will look back at this vote as one of their finest, proudest moments," Bloomberg said in a statement released shortly after the vote.