CONCORD, N.H. - New Hampshire became the sixth state to legalize same-sex marriage after its Senate and House passed key language on religious rights and Gov. John Lynch - who personally opposes same-sex marriage - signed the legislation yesterday afternoon.

After morning rallies by both sides outside the Statehouse, the last of three bills in the package went to the Senate, which passed it, 14-10. Cheers from the gallery greeted the key vote in the House, which approved it, 198-176.

"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," the governor said.

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

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

California briefly allowed same-sex marriage before a public vote banned it; a court ruling grandfathered in couples who had already wed.

The New Hampshire law will take effect Jan. 1, exactly two years after the state began recognizing civil unions.

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.

Opponents, mainly Republicans, objected on grounds including the fragmented process. "When you take 12 votes on five iterations of the same issue, you're bound to get it passed sooner or later," said Kevin Smith, executive director of gay-marriage opponent Cornerstone Policy Research.

The revised bill specifies that all religious groups, associations, or societies have exclusive control over their religious doctrines, policies, and teachings on marriage.

The law will establish civil and religious marriage licenses and allow each party to the marriage to be identified as bride, groom, or spouse. Same-sex couples already in civil unions will automatically be assumed to have a "civil marriage."

Churches will be able to decide whether to conduct religious marriages for same-sex couples. Civil marriages would be available to both heterosexual and same-sex couples.