BOSTON - The Massachusetts Legislature rejected yesterday a proposed constitutional amendment that sought to ban gay marriage but legalize civil unions, a year after the state performed the nation's first government-sanctioned same-sex weddings.

It was the second time the Legislature had confronted the measure, which was intended to be put before voters on a statewide ballot in 2006. Under state law, lawmakers were required to approve it in two consecutive sessions before it could move forward.

After less than two hours of debate yesterday, a joint session of the House and Senate voted 157-39 against the measure.

The moment the vote was announced, cheers erupted from gay marriage supporters who watched the proceedings from the House chamber's public gallery.

"We have a lot of work ahead of us, but today we celebrate," Sen. Jarrett Barrios, a Democrat and openly gay lawmaker, told the cheering crowd.

Opponents of gay marriage also declared victory, saying the defeat of the amendment paves the way for the launch of a second, more restrictive proposed amendment that would ban gay marriage and civil unions. The earliest that could get on the ballot is 2008.

"We're excited. We're pumped. This is great. This is exactly what we wanted," said Kris Mineau, president of the Massachusetts Family Institute.

Yesterday's vote was a striking departure from a year earlier, when hundreds of protesters converged on Beacon Hill and sharply divided legislators spent long hours debating the issue. In that session, in March 2004, lawmakers voted 105-92 in favor of the amendment.

This year, the crowds were tamer and some legislators who had initially supported the proposed change to the state constitution said they no longer felt right about denying the right of marriage to thousands of same-sex couples.

"Gay marriage has begun, and life has not changed for the citizens of the commonwealth, with the exception of those who can now marry," said state Sen. Brian Lees, a Republican who had been a co-sponsor of the amendment. "This amendment which was an appropriate measure or compromise a year ago, is no longer, I feel, a compromise today."

The state's highest court ruled in November 2003 that same-sex couples had a right under the state constitution to marry. The first weddings took place on May 17, 2004 - two months after lawmakers began trying to change the constitution to reverse the court's ruling.

Since then, more than 6,100 couples have married. However, Massachusetts barred out-of-state couples from getting married here, citing a 1913 law that prohibits couples from marrying in Massachusetts if their union would be illegal in their home states. A lawsuit challenging that law is pending before the Supreme Judicial Court.