At one point, dozens of opponents of gay marriage knelt and prayed amid the din.

The debate began with consideration of an unexpected amendment, proposed at the last minute by House Speaker Thomas Finneran, that would have banned gay marriage but allowed the Legislature to adopt civil unions.

After two hours of debate and accusations that the Democratic speaker was trying to hijack the process, that amendment was shot down by a 100-98 vote.

Debate then turned to the Senate compromise, which suffered the same fate.

In arguing against the gay-marriage ban, Sen. Dianne Wilkerson drew upon her experience as a black woman growing up in Arkansas, where the hospital did not allow her mother to deliver her children.

"I know the pain of being less than equal and I cannot and will not impose that status on anyone else," a teary-eyed Wilkerson said. "I could not in good conscience ever vote to send anyone to that place from which my family fled."

Supporters of a ban called for the Legislature to respect 3,000 years of tradition.

"Every society, every culture, every nation in all of recorded history, including Massachusetts, has up until this point at least defined marriage as one man and one woman," Finneran said.

The Legislature is tightly controlled by the Democrats, who hold 169 of 199 seats. (One seat is vacant.) The Legislature is also heavily Roman Catholic.

The votes will force lawmakers to declare their stand on a divisive social issue that most would prefer to avoid, especially with all 200 legislative seats up for grabs at the November elections.

If gay marriage takes place in Massachusetts, federal lawsuits would probably ensue as gay couples seek recognition in other states and by the federal government.

While marriages performed in one state are normally recognized in other jurisdictions, 38 states and the federal government have approved laws or amendments barring the recognition of gay marriage.

In California, a state lawmaker plans to introduce legislation this week that would legalize gay marriage in that state.