Hillary Rodham Clinton in 2013, as she endorsed Virginia gubernatorial candidate Terry McAuliffe, right. Mark Herring stands at left, with Ralph Northam. (Bill O'Leary/Washington Post)

Lately in Virginia, it’s good to be the attorney general.

While Gov. Terry McAuliffe (D) has been hamstrung by a hostile, Republican-controlled General Assembly, Attorney General Mark R. Herring (D) has been pulling off feats of political ­derring-do — sometimes with just the stroke of a pen.

Herring announced last week that he would take a pass on the 2017 governor’s race and run for reelection instead, opting to aim for four more years in a job that allows for gutsy legal maneuvers rather than one saddled with legislative gridlock.

Herring has witnessed the governor’s frustrations, people close to the attorney general said, particularly as they searched jointly and fruitlessly last year for a way to expand Medicaid under the Affordable Care Act after the proposal was rejected by the General Assembly.

At the same time, from his corner of Capitol Square, Herring was able to abruptly reverse the state’s policies on gay marriage, in-state tuition for illegal immigrants and building standards for abortion clinics.

That is not to say that deep inside, Herring has no desire to see himself ensconced in Virginia’s Executive Mansion someday. Or that his desire to stay put for now is not based on many factors, including a perception that the term-limited McAuliffe has been quietly rooting for a different successor, Lt. Gov. Ralph Northam (D).

But Herring’s decision demonstrates the immense power of the attorney general’s job, at least under his expansive interpretation of it. And it also reflects how much Richmond, like gridlocked Washington, has become a place where big change is more likely to come from swashbuckling legal or executive actions than from legislative give and take.

“There really was a ‘wow’ factor to his first year in office,” said Ellen Qualls, a Herring adviser. In Virginia, “Democrats haven’t had the attorney general’s office for 20 years, and I think we sort of forgot what you can do with it.”

Herring is sure to draw a GOP opponent in his quest for a second term. Del. Robert B. Bell (R-Albemarle), who ran in 2013 but lost in the primary, is considered a likely candidate.

In announcing that he would run for reelection, Herring also acknowledged the reality that what one attorney general can deliver, another can take away. “Our hard-won progress is as fragile as the next election,” he said.

A. E. Dick Howard, a University of Virginia law professor and constitutional scholar, said partisan gridlock in Richmond means “the attorney general in some way is able to make more impact on the shape of Virginia law and policy than the governor. It makes perfect sense to me for an attorney general, who’s able to run for reelection and who can act without the fetters of dealing with the other branch, to make that decision.”

Even so, much of Virginia’s political class has been puzzled by Herring’s move — former governor L. Douglas Wilder (D) called it decision “shocking.”

During his 2013 campaign for attorney general, Herring pledged to take politics out of the office — a swipe at the aggressively conservative tenure of his immediate predecessor, Republican Ken Cuccinelli II (who ran for governor after one term but lost to McAuliffe).

But Herring’s critics say he has since become the liberal flip side to Cuccinelli’s activism, exceeding his authority and subverting the rule of law in pursuit of Democratic goals.

His reelection announcement drew instant pushback from conservatives, including Charlottesville-based talk radio host Joe Thomas, who tweeted that the attorney general wants to “keep on NOT enforcing #VA laws.”

Herring maintains that all of his actions have been “firmly grounded in the law,” as he put it last week. He declared the state’s ban on gay marriage unconstitutional before the Supreme Court legalized same-sex marriage nationwide but said he was building upon earlier high court rulings that signaled the justices were headed that way.

His decision on in-state tuition followed an Obama administration decree — hotly contested in its own right — to treat some illegal immigrants as if they were in the United States legally under certain conditions.

Political observers had widely expected Herring to use his headline-generating record to launch a gubernatorial bid. The only declared candidate in the race so far is Northam, who announced in February. Given the lieutenant governor’s relatively low profile, the attorney general was widely considered to have the advantage in a Democratic primary.

But Northam has something that Herring does not: a close relationship with McAuliffe. The lieutenant governor sits in on McAuliffe’s weekly cabinet meetings, often serves as his surrogate and, with his wife, frequently socializes with the governor and first lady.

Herring and McAuliffe, in contrast, do not have a strong personal rapport. Relations between their offices sometimes appear strained, with big announcements from one occasionally catching the other by surprise, according to legislators and staff who work with both.

Spokesmen for McAuliffe’s office and political action committee did not respond to requests for comment on the governor’s relationship with the attorney general and his office. Herring spokesman Michael Kelly said there was no tension between the offices, noting that they have worked together on a daily basis.

Some people close to Herring say McAuliffe’s perceived preference for Northam was not a factor in his decision. But backing from the governor surely has the potential to provide an edge in the race, especially given McAuliffe’s vast political network as a longtime fundraiser for both Bill and Hillary Rodham Clinton.

Qualls said Herring made his decision privately, on his own terms.

“It’s not like we had a giant strategy summit and he decided at the end,” she said. “I literally think he was mowing his lawn one day and decided.”