WASHINGTON — 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 last week as Virginia Attorney General Mark Herring, a Democrat, 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 will not 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,’’ Canter said.
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 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 won by 907 votes out of 2.2 million cast.
Conservative activists say they still think 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.’’