New Hampshire has become the sixth state to legalize same-sex marriage.
Governor John Lynch, who personally opposes gay marriage, signed the legislation on Wednesday.
The governor had threatened a veto unless the law spelled out that churches and religious groups would not be forced to officiate at gay marriages or provide other services.
The amended bill reflects those changes.
"They strike the appropriate balance between two important values that we believe New Hampshire residents support equal rights for all and the right to religious freedom," said State Sen. Deborah Reynolds.
The new law will take effect on January 1.