Attorney General Mark Herring, left, and Lt. Gov. Ralph Northam appeared with Gov. Terry McAuliffe and Hillary Rodham Clinton at a fundraiser during the 2013 campaign. (Bill O'Leary/The Washington Post)

Virginia Attorney General Mark R. Herring announced Wednesday that he will seek a second term as the state’s top lawyer, helping to clear a path for low-profile Lt. Gov. Ralph S. Northam to become the Democrats’ 2017 gubernatorial nominee.

The surprise move could enable the party to avoid a potentially bruising primary fight. It ends months of speculation that Herring — an outspoken advocate for same-sex marriage, abortion rights and immigration reform — was preparing to run for the state’s highest office.

But Northam’s candidacy also presents some risks for Democrats, who relied on partisan spitfire Terry McAuliffe to excite the party’s base when he ran for governor in 2013. Last year, U.S. Sen. Mark R. Warner (D) barely beat back a Republican challenger with his “radical centrist” mantra.

A mild-mannered veteran and a doctor with a moderate image, Northam could be more appealing to independents than Herring, whose aggressive moves to advance liberal causes have made him a political lightning rod. But politicians on both sides of the aisle noted that in off-year elections in the increasingly polarized state, partisan fervor sometimes trumps broad-based appeal.

Politicians in Virginia often use the attorney general’s post as a springboard to the governor’s mansion — so often that commonwealth politicos quip that “AG” stands for “almost governor.”

Mark Herring announced Wednesday that he will seek reelection to his current post in 2017. (Joe Mahoney/AP)

But Herring said he decided to endorse Northam and run for a second term as attorney general after several months of deliberations, in part to make sure that the liberal victories he has won in his first term are not reversed by his successor.

“This was all about choosing to do a job that I absolutely love, and nobody put any pressure on me,” Herring said. “I have shown Virginians just what an attorney general can do for them. I’m really proud of the record we’ve accomplished and look forward to continuing to do that great work.”

Northam said that he met with Herring for about 30 minutes Monday and that his former Virginia Senate seatmate was “very gracious.”

“This puts to rest some of the uneasiness that was out there with our base in terms of who will do what,” the lieutenant governor said. “I don’t think anybody in our party that is really involved wants to see fellow Democrats opposing each other in a primary.”

McAuliffe immediately endorsed Herring’s reelection bid, calling him “fearless and fiercely committed to promoting justice, equality, and opportunity for all Virginians.” The governor’s statement did not mention Northam, who could still face competition for the nomination.

No other Democrats have said they will run since Northam confirmed his plans to do so in February. But other names have been floated, including that of Rep. Gerald E. Connolly (D).

On Wednesday, Connolly said that he wouldn’t rule out a bid. “Life is a moving stream, and who knows where it takes you,” he said.

Many Democrats said they were relieved by Herring’s decision even though his headline-grabbing stint as attorney general has given him higher name-recognition than Northam.

Northam, a Virginia Military Institute graduate, Gulf War veteran and pediatric neurologist who hunts, fishes and speaks with the drawl of an Eastern Shore native, could have greater appeal to swing voters, his supporters have said.

Another understated politician, state Sen. Mark D. Obenshain (R-Rockingham), is regarded as a top Republican gubernatorial contender but has not announced a run.

A Northam-Obenshain race would be radically different, political observers say, than the 2013 contest between McAuliffe and then-attorney general Ken Cuccinelli II (R) — two flamboyant personalities.

“You’d go from a situation where you had two people who evoked extraordinarily strong feelings to people who would be striving to evoke feelings,” said former Virginia Commonwealth University political scientist Bob Holsworth. “They’re both extremely decent, understated, serious individuals . . . neither of whom absolutely relishes the in-your-face nature of modern politics.”

In 2008, as a newly elected state senator, Northam angered some Democrats when he crossed party lines to end an impasse over judicial appointments. Thinking they had a sympathetic ear, Republicans asked him to switch parties. He declined, and in recent years, he has moved with his party to embrace such issues as same-sex marriage.

But Northam retains a moderate image. In the state Senate, where he presides in his role as lieutenant governor, he enjoys friendly relations with Republicans — despite some tie-breaking votes that have angered them.

Some Democrats say that Northam is well-positioned to capture some of the rural white voters who have left the party in droves in recent years. But others question whether his folksy approach can work in 21st century, purple Virginia.

“In a post-Barack Obama world, where you fire up your base, I think Herring would have been a better candidate,” said Pete Snyder, a Northern Virginia technology entrepreneur who unsuccessfully sought the GOP nomination for lieutenant governor in 2013.

Said former Republican congressman Tom Davis: “This is a turnout-driven state, and Democrats will win this thing when they can dominate turnout, as they have the last two presidential elections.”

Mo Elleithee, executive director of Georgetown’s Institute of Politics and Public Service and a former DNC communications director, said that Herring’s decision to skip the race will shine a spotlight on Northam, at least for a while.

“He still has to prove that he understands the new Virginia,” Elleithee said. “And I think he can. But for a lot of Democrats who were excited about Mark Herring, they’re now going to be looking at Ralph Northam and saying, ‘Okay, we’re willing to give you a shot, but show us what you got.’ ”