CONCORD, N.H. - New Hampshire yesterday became the sixth state to legalize gay marriage, in a move that reflects the state's changing demographics from reliably Republican and conservative to younger and more liberal.

The Senate and House passed key language on religious rights. Gov. John Lynch - who personally opposes gay marriage - signed the legislation yesterday afternoon.

Lynch, a Democrat, had promised a veto if the law didn't clearly spell out that churches and religious groups would not be forced to officiate at gay marriages or provide other services. Legislators made the changes.

"Today, we are standing up for the liberties of same-sex couples by making clear that they will receive the same rights, responsibilities - and respect - under New Hampshire law," Lynch said.

Massachusetts, Connecticut, Maine, Vermont and Iowa already allow gay marriage, though opponents hope to overturn Maine's law with a public vote.

California briefly allowed gay marriage before a public vote banned it; a court ruling grandfathered in couples who were already married.

After rallies outside the Statehouse by both sides in the morning, the last of three bills in the package went to the Senate, which approved it 14-10 yesterday afternoon.

Cheers from the gallery greeted the key vote in the House, which passed it 198-176. Surrounded by gay-marriage supporters, Lynch signed the bill about an hour later.

The New Hampshire law will take effect Jan. 1.

The Rt. Rev. V. Gene Robinson, elected in New Hampshire in 2003 as the first openly gay bishop in the Episcopal Church, was among those celebrating the new law.

"It's about being recognized as whole people and whole citizens," Robinson said. *