To some extent, the support for same-sex marriage reflects a sea change in New Hampshire politics since 2006, when Democrats gained control of the legislature for the first time in over a century. While staunchly conservative on fiscal matters, New Hampshire has been less so on social issues, partly because its residents’ famous libertarian streak resists government intrusion in personal matters.

But last-minute politicking also played a role in the Senate’s vote. Last week the Senate Judiciary Committee voted 3 to 2 against the marriage measure, and the committee’s chairwoman, Senator Deborah Reynolds, a Democrat, said afterward that New Hampshire was simply not ready for same-sex marriage.

Ms. Reynolds, the only Democrat who opposed the bill in committee, emphasized that civil unions were still new in New Hampshire and that Vermont, whose legislature approved same-sex marriage on April 7, had done so only after living with civil unions for nine years.

But on Wednesday, Ms. Reynolds, who represents a fairly conservative region, said the new language made the bill acceptable. She described it as a compromise that was “respectful to both sides of the debate and meets our shared goals of equality under the state laws for all of the people of New Hampshire.”

Gov. Jim Douglas of Vermont, a Republican, vetoed that state’s same-sex marriage bill, but the Democratic-controlled legislature overrode his veto, making Vermont the first state to adopt same-sex marriage legislatively instead of through the courts. Days earlier, the Iowa Supreme Court found a state law banning same-sex marriage to be a violation of the State Constitution.

In New Hampshire, more than 650 same-sex unions have been registered since they became legal in January 2008.

Same-sex marriage was among several contentious bills that the Senate took up Wednesday, all passed by the House in recent weeks. One, a measure to allow people with certain illnesses to possess marijuana for medical purposes, passed in a vote of 14 to 10. But the Senate voted unanimously against a bill that would guarantee transgender people protection from discrimination in housing and employment. It also put off action on a bill to repeal the death penalty.