Correction: An earlier version of this story incorrectly reported the drop of Sen. Rob Portman’s (R-Ohio) approval rating since announcing his support for same-sex marriage.

Public opinion on same-sex marriage has shifted so dramatically in recent years that Democratic groups now see the issue as a critical way to mobilize voters in a slew of races up and down the ballot.

Just a decade ago, widespread opposition to gay marriage did just the opposite, allowing Karl Rove to mobilize conservatives in 13 states and help reelect George W. Bush as president.

The changing political dynamics were on full display this week as Virginia Attorney General Mark R. Herring (D) announced he would not defend the state’s ban on same-sex marriage on the grounds that it was unconstitutional. Herring won a close election with strong support from gay-rights groups, and his decision infuriated conservatives, who accused him of violating his oath to uphold state laws.

Ballot initiatives on same-sex marriage are already in the works in Oregon, and possibly Indiana and Ohio, this fall. The issue is also expected to figure prominently in an array of congressional and state races across the country.

Democrats say they are confident that the issue will help them in many blue and purple states, and they believe it won’t hurt them much in red states, either.

“There isn’t a single Republican big-money group that spends significant resources in Senate races that has even been willing to say on the record, ‘Yes, we will campaign on discrimination and bigotry and attack Democrats who support equality,’ ” said Matt Canter, spokesman for the Democratic Senatorial Campaign Committee. “I can only assume that these groups recognize that they risk sounding hateful and out of touch on issues that matter in this election if they were to pursue such a strategy.”

The Republican side is more divided. The party remains officially opposed to legalizing same-sex marriage, a position strongly backed by religious conservatives who form a key part of the base. But some Republican leaders say they do not expect the issue to be central in most midterm contests.

“I’m not sure of any races where this is an issue,” Republican National Committee spokeswoman Kirsten Kukowski wrote in an e-mail.

The wave of change has been driven in part by federal court rulings, including decisions in recent weeks striking down same-sex marriage bans in two deeply conservative states, Oklahoma and Utah. More than 1,000 couples were married in Utah before the Supreme Court on Jan. 6 granted the state’s request to stop the marriages while an appeal is considered.

Seventeen states and the District of Columbia allow same-sex marriages, up from nine states a year ago.

“As more Oklahomas and Utahs bubble up, it is going to be a question that is increasingly asked” of politicians, said Fred Sainz, a spokesman for the Human Rights Campaign. “It will come up as a question, but not a cudgel, in races.”

Gay-marriage advocates such as Sainz contend that the issue works to their advantage because of greater intensity on their side. In the Virginia race between Herring and Republican Mark D. Obenshain, one Fairfax County voter who fought successfully to have his provisional ballot accepted told Herring he followed through because of his views on same-sex marriage.

“I am gay, and I got an e-mail from the Human Rights Campaign urging me to vote for you,” the voter told Herring in a phone message, according to the attorney general’s aides. “I want you to win to protect not only my rights, but everyone’s rights.”

Herring ended up winning by 907 votes out of 2.2 million cast.

Same-sex marriage can bring progressive voters to the polls. When Minnesota rejected a constitutional amendment to ban gay marriage 2012, the proposal received more votes, pro and con, than were cast in the presidential contest.

Conservative activists say they still believe the gay-marriage debate can work in their favor, especially in midterm elections, which lean more conservative. Ralph Reed, founder and chairman of the Faith & Freedom Coalition, said the issue gives Republicans “a bridge to nontraditional constituencies and voters, especially African Americans.”

Although Minnesota and Maryland voted on gay-marriage initiatives in 2012, Reed noted that the margin of victory was smaller than the one President Obama enjoyed over GOP presidential nominee Mitt Romney in those states. “The idea that this is a drag on the party is just laughable,” he said.

Elected officials in more liberal states rarely pay a price for endorsing same-sex marriage, but it remains unclear how it will play out in more conservative states. In North Carolina, Sen. Kay Hagan (D) has come under fire from one of her potential Republican opponents, Charlotte pastor Mark Harris, for making “a fatal mistake” by announcing in March she supported the right of gay couples to marry.

North Carolina Attorney General Roy Cooper (D), a potential 2016 gubernatorial candidate, has also backed gay marriage but is still defending the state’s ban in court.

“North Carolina should change its laws to allow marriage equality, and I believe basic fairness eventually will prevail,” Cooper said in a statement. “However, when legal arguments exist to defend a law, it is the duty of the Office of the Attorney General under North Carolina law to make those arguments in court.”

Reed’s group plans to use the issue to appeal to Christian voters in North Carolina and other

conservative-leaning states that have senators up for reelection, including Arkansas and Louisiana. “It will be an issue in every one of these states,” Reed said.

In Ohio, a push for a ballot initiative as soon as this year has caused heartburn on both sides because public opinion is in flux. A decade after 62 percent of Ohio voters approved a constitutional ban on same-sex marriage, a recent Quinnipiac poll showed a narrow majority now backs gay-marriage rights.

At the same time, the poll showed that Sen. Rob Portman’s (R) approval rating has dropped since he announced his support for same-sex marriage, by three points overall and six points among Republicans.

“We’re talking about some very hard-and-fast beliefs that don’t switch on and off like a light,” says Mike Premo, campaign manager for Why Marriage Matters Ohio.

Gay-rights proponents are likely to pour money into several key state races to bring more attorneys general over to their side, including open-seat races in Colorado and Nevada. Both states allow civil unions for same-sex couples, but not marriage.

The general election in 2016 is likely to feature another wave of ballot initiatives in several states, including Nevada and Michigan, which could have ripple effects up and down the ballot.

Some proponents of keeping marriage between one man and one woman say they are more focused on the court fights than elections, however.

“There’s a short time window for these lawsuits to reach the Supreme Court,” said the National Organization for Marriage’s Brian S. Brown, whose group is pushing for an amendment to the U.S. Constitution that would ban same-sex marriage. “The number one issue is to make clear to the Supreme Court that the people will not take another Roe v. Wade decision without fighting back.”

Niraj Chokshi and Robert Barnes contributed to this report.