A bill to legalize same-sex marriage won narrow approval Friday night in the Maryland House of Delegates, setting the stage for the state to join seven others and the District in allowing gay nuptials.

The 72 to 67 vote, which followed a day of emotional and contentious debate, capped a dramatic turnaround from a year ago and all but assures the measure will be sent to Gov. Martin O’Malley (D) for his promised signature.

The bill passed with one vote to spare and moves to the Senate, which approved similar legislation last year. But Maryland voters could get the final say: Opponents are widely expected to launch a petition drive that could put the issue on the November ballot.

“We should extend to families, same-sex loving couples, the right to marry in a civil ceremony,” Del. Maggie L. McIntosh (D-Baltimore), one of seven gay House members, told a hushed chamber Friday night after relaying her experience of coming out as a lesbian. “I’m going to ask you today, my colleagues, to make history.”

Maryland’s move toward same-sex marriage comes amid a fresh wave of momentum nationally for gay-rights activists.

Gay nuptials bills were signed by the governors of New York in June and Washington state this month, and a federal appeals court this month declared California’s ban on same-sex marriage unconstitutional. And this week, the New Jersey legislature sent Gov. Chris Christie (R) a same-sex marriage bill. Christie, who has said the issue should be put before voters, vetoed the bill Friday.

In Annapolis, O’Malley and other supporters scrambled in recent days to nail down enough votes to avoid a repeat of last year, when the legislation died on the House floor. After this year’s vote, an impromptu victory celebration spilled into the hallway between the two legislative chambers in the State House.

O’Malley’s efforts were buoyed by the support of two Republican delegates who announced their backing of the legislation this week: Robert A. Costa of Anne Arundel County and A. Wade Kach of Baltimore County.

In Friday’s debate, supporters hailed the measure as a major step forward in equal rights, with some relaying deeply personal stories. Opponents decried the redefinition of “marriage” and said it was an affront to long-standing religious traditions.

Kach told the chamber that his views on the issue changed after a hearing last week, when he heard testimony from same-sex couples, including some with children. “My constituents did not send me here to judge people,” Kach said.

In the hours before the bill passed, its prospects had appeared clouded by the hospitalization Thursday of a key supporter, Del. Veronica L. Turner (D-Prince George’s).

Both chambers of Maryland’s legislature are heavily Democratic, but the bill proved a tough sell among African American lawmakers from the party, including many Prince George’s delegates, who cited opposition by churches and constituents in their districts.

Twenty-six Democrats and 41 Republicans voted against the bill.

“Same-sex marriage is wrong,” Del. Emmett C. Burns Jr. (D-Baltimore County), told the chamber before the vote. “I believe that people who are gay have a right to be that, but the word ‘marriage’ should not be attached.”

Burns joined several Republicans in vowing to defeat the measure on the ballot.

Social conservatives have succeeded in putting another hot-button issue to voters in November: a law passed last year that would grant in-state tuition breaks to certain children of illegal immigrants. On Friday, opponents vowed to replicate those efforts on the same-sex marriage bill.

“When we take this vote, we will be beginning a process and not ending a process,” said House Minority Leader Anthony J. O’Donnell (R-Calvert). “The citizens of Maryland will have the final say.”

A Washington Post poll last month found that half of Maryland residents favor the legalization of gay marriage, but support varies significantly along the lines of race, religion and age. Overall, the poll found that 50 percent of Marylanders support allowing gay and lesbian couples to marry and 44 percent are opposed.

One of the unexpected supporters Friday was Del. Tiffany T. Alston (D-Prince George’s), who co-sponsored last year’s bill but withdrew her support in response to what she said was strong opposition in her district.

On Friday, Alston said she was satisfied that the bill would be petitioned to the ballot. Under an amendment that she proposed, the House agreed that same-sex marriages could not begin if legal challenges to the signature-gathering process were still pending.

“Right now, as a state, it’s time for us to move beyond the issue,” Alston told her colleagues. “I think the community needs to vote on this.”

House Speaker Michael E. Busch (D-Anne Arundel), who characterized Friday night’s vote as “historic,” said Alston took the initiative in talking to House leaders about supporting the bill.

“She brought herself in,” Busch said. “She labored long and hard over the issue. It was a courageous vote on her part.”

Friday’s vote marks a victory for O’Malley, who previously supported civil unions as an alternative to same-sex marriage. The governor agreed to sponsor this year’s bill in July, in the wake of its failure in the House last year.

O’Malley said his reworked legislation provided greater protections for religious organizations opposed to gay nuptials.

“There is still work to be done, and marriage equality has not yet been achieved in Maryland,” O’Malley said in a statement released after the vote. “Wherever we happen to stand on the marriage equality issue, we can agree that all our children deserve the opportunity to live in a loving, caring, committed and stable home, protected equally under the law.”

Besides criticizing the outcome, opponents of the bill also took issue Friday with the process, accusing House leaders of muscling the legislation through the chamber once they had secured just enough votes.

In a statement, the Maryland Catholic Conference, one of several religious groups that opposes the bill, said it would turn its attention to the Senate.

“We urge them to give reasoned and honest consideration to the inevitable conflicts that passing this bill will create between government and religious communities,” the organization said. “We urge them to allow the time that the House leadership denied to ensuring this issue will be treated with the serious and well thought-out examination it deserves.”

The unofficial vote tally released at the time of Friday’s vote showed 71 “yeas,” the bare number needed for passage in the 141-member chamber. The number was later increased by one to reflect the support of Del. John L. Bohanan Jr. (D-St. Mary’s), whose vote was not recorded properly.

During debate Friday, delegates rejected a proposed amendment, 78 to 45, to legalize civil unions rather than same-sex marriage.