The Minnesota House of Representatives on Thursday voted to permit same-sex marriage, clearing the way to add Minnesota to a string of states that have recently made it legal for gay and lesbian couples to wed.

The House, which is controlled by Democrats, approved the measure 75-59, dividing mostly along party lines.

In recent months, as the debate over same-sex marriage emerged in St. Paul, a capital newly dominated by Democrats, the outcome in the House had been seen as most uncertain. State Senate leaders say that the outlook is more assured in that chamber and that they expect to approve same-sex marriage next week. Gov. Mark Dayton, a Democrat, urged approval and said he would sign the bill, which would allow same-sex marriages starting Aug. 1.

If the measure is approved, Minnesota would become the 12th state, in addition to the District of Columbia, to permit marriages for gay and lesbian couples and the third to decide to do so, along with Delaware and Rhode Island, this month alone.

Minnesota would also become the first state in the middle of the nation to make such a choice through legislative action. Elsewhere in the Midwest, Iowa allows same-sex marriage, but that was decided in the courts. In Illinois, which allows civil unions, state House members are considering a same-sex marriage bill already approved in the state Senate.

In a way, the vote here came as a remarkable shift. Just a few months ago, in November, voters had cast ballots following a hard-fought campaign aimed at amending the state constitution to define marriage as between a man and a woman. The amendment failed, and, with Democrats winning control of both legislative chambers in the same election, a renewed effort to allow same-sex marriage emerged.

Dueling campaigns — an RV tour, rallies, leaflets and advertisements — have consumed the state in recent weeks.

“This is a historic day for Minnesota,” Rep. Karen Clark, a Democrat and the bill’s sponsor, said as House members debated the issue before the vote and as advocates on both sides crowded into the Capitol, chanting and cheering. “Freedom means freedom for everyone,” she said.

The debate lasted for several hours, sometimes growing emotional and personal.

“I am not a homophobe or a Neanderthal or a hater,” said Rep. Tony Cornish, a Republican, explaining why he would vote against the measure. “My constituents back home, the majority of them wanted me to vote that way,” he said.

In the weeks before the vote, supporters of same-sex marriage said they were hoping to win support from at least a few Republicans and from Democrats who represent more rural districts, where the issue was more contested, far from the Twin Cities. In the end, four Republicans voted for same-sex marriage, officials said, and two Democrats opposed it.

“Sometimes,” said Rep. Raymond Dehn, a Democrat who supported the measure, “it gets down to doing the right thing.”

Opponents said lawmakers had misunderstood the feelings of Minnesotans, and had misinterpreted voters’ rejection in November of the constitutional amendment to mean that they now wanted to legalize same-sex marriage. Others said that same-sex marriage remained too divisive, too much of a diversion from the fiscal issues that voters truly wanted answered in St. Paul.

Rep. Kelby Woodard, a Republican who voted no, warned supporters about the size and significance of marriage.

“We are redefining an institution that has been the bedrock of our society for generations,” he said. “We’re asked to empathize with the idea that we should redefine marriage, and I’m asking you to empathize with at least half of Minnesotans who disagree with that. Think about them as well.”