Correction: Earlier versions of this article misstated the date when Maryland Gov. Martin O’Malley announced his support for same-sex marriage legislation.

Voters in Maryland narrowly upheld the state’s same-sex marriage law, a historic victory for the national gay-rights movement that highlights the country’s evolving definition of marriage.

Before Tuesday, gays and lesbians had been granted the right to marry by courts and state legislatures, but proponents of marriage had been defeated at the ballot box in more than 30 states.

Maryland women engaged moments after measure is approved.

Maryland was joined by Maine in approving gay marriage, making the two states’ voters the first in the country to approve the measures by a popular vote. Voters in Minnesota rejected a constitutional amendment that would have banned same-same sex marriage.

In Maryland, gay couples will be able to wed starting Jan. 1.

As they watched the results at a Baltimore club and sensed victory, Ruth Siegel and Nina Nethery, together for 15 years, said they felt joyous. They were surrounded by hundreds of supporters of the referendum to legalize same sex marriage.

“It’s being part of history,” said Nethery, 59, a systems analyst who lives with Siegel in Silver Spring. “ I’m in history.”

Several of the votes — most notably Question 6, the same-sex marriage measure — carried political consequences for Gov. Martin O’Malley (D). Marylanders were asked whether to affirm the gay marriage law championed this year by the governor that was put on hold after opponents gathered enough signatures to force a public vote.

Maryland and Maine join six other states and the District where same-sex marriage has been legal.

Voters in Washington also considered a measure to allow gay nuptials Tuesday. With just over 51 percent of precincts reporting, votes in favor of the measure were slightly ahead of votes against it, but the contest remained to close to call.

In brief remarks to a boisterous crowd in Baltimore, O’Malley, who championed the measure, described a campaign for marriage equality as a “noble battle to move Maryland forward.”

Anthony Valenzuela, 37, standing with his partner, Kent deJong, 51, said the referendum’s passage signifies that “Maryland is a pathfinder for other states. It means that the people can decide in favor of love.”

The couple said they expect to get married next year, perhaps in Iowa where deJong has family. “It allows society to recognize us as a couple,” deJong said. “Its an affirmation.”

In the first election since President Obama’s endorsement of same-sex marriage, a popular-vote win will now change the dynamics of the debate going forward, gay-rights activists said.

“It takes away the talking points that anti-marriage activists use day in and day out: that this issue can’t win at the ballot box,” said Chad Griffin, president of the Human Rights Coalition, the nation’s largest gay-rights organization.

Griffin attributed the success to a new, carefully assembled coalition that united gay-rights advocates with officials at the NAACP, with clergy, and with businesses and philanthropists who hadn’t previously contributed to the gay-rights causes.

Brian Brown, president of National Organization for Marriage, which fought the measures in both Maine and Maryland, conceded defeat.

“It’s very, very close, but look at the numbers in Maryland that went for Obama, and look at the numbers for us,” he said. “They barely won. We won by a much larger margin than Mitt Romney or any of the Republicans.”

In Maryland, partial returns showed the measure with a nearly 2-to-1 lead in Montgomery County and trailing slightly in Prince George’s. Support was far weaker in the more rural parts of the state.

Voters who attend church at least weekly were far more likely to be opposed than those who attend occasionally or never, according to the exit polls. Women were more likely to support the measure than men, and white voters were more likely to support it than African Americans, who split about evenly.

The campaign over Question 6 in Maryland focused heavily on African American voters, who make up a larger share of the electorate than in any other state outside the Deep South and whom polls showed as more reluctant to accept gay nuptials than white voters.

Television and radio ads aired by Marylanders for Marriage Equality, an O’Malley-backed campaign group, featured testimonials about fairness from black ministers and civil rights leaders. As of two weeks ago, the group had raised $4.5 million for its efforts, more than two and half times as much money as the leading opposition group, the Maryland Marriage Alliance, had raised for its bid to defeat Question 6.

O’Malley cast the issue in terms of equal protection, saying at a news conference Monday that Question 6 would “protect every child’s home equally under the law.” O’Malley also argued that he and lawmakers went to great lengths to include provisions in the law that protect the religious liberties of those who oppose it.

Opponents spent months networking through black and Catholic churches, trying to convert strength in the pews to muscle at the ballot box. Their less-frequent ads warned of changes to school curriculum and other consequences if voters redefined marriage.

At an event last week featuring about 75 religious leaders opposed to Question 6, Derek McCoy, the leader of the opposition group, argued that “marriage is more than what any two adults want. It is about future generations and our culture.”

The battle in Maryland drew an array of celebrities from across the country, with most offering fundraising help for supporters of same-sex marriage.

Before Tuesday, same-sex marriage was legal in the District and six states: Massachusetts, Vermont, Connecticut, New Hampshire, Iowa and New York.

Tuesday’s ballot measure in Washington state bears the most similarities to Maryland’s. In those states, legislatures passed a measure that petitioners pushed to a popular vote. A mail-in voting procedure in the Evergreen State means that final results there won’t be known till week’s end.

It had been three years since voters in any state were asked whether to legalize same-sex marriage — in 2009, Maine voters narrowly repealed a law to allow it that had been passed by the legislature.

This month, the U.S. Supreme Court will decide whether to take up several tests of same-sex marriage.

For much of his political career, O’Malley, a practicing Roman Catholic, had been on record as supporting civil unions as an alternative to gay nuptials.

O’Malley announced his support of same-sex marriage legislation in July 2011, a few months after a similar bill passed the Maryland Senate but unexpectedly fell short in the House of Delegates. This year, with O’Malley’s backing, the same-sex marriage bill passed the House with one vote to spare.