Virginia has quietly rehired a private law firm that state Attorney General Mark R. Herring fired a few days after taking office, a move that provides about two dozen former state employees with legal representation in the corruption trial of former governor Robert F. McDonnell and his wife.

Gov. Terry McAuliffe’s decision to put Baker & McKenzie back on the state payroll reverses the first headline-grabbing move of Herring’s short but high-profile tenure, during which the Democrat has upended the state’s position on gay marriage and its policy on college tuition charged to illegal immigrants.

Herring’s office trumpeted the firm’s firing in a news release in January, but there was no announcement when McAuliffe (D) rehired it in March.

The firm’s name appeared this week on subpoenas calling about two dozen McDonnell Cabinet secretaries, senior staff members and governor’s mansion employees to testify in the case, which is scheduled to go to trial July 28.

“The governor’s office decided that the staff that were at risk of legal expenses as a result of the McDonnell trial should have continued representation,” McAuliffe spokesman Brian Coy said.

Coy said there were a lot of McDonnell staffers who, through no fault of their own, could be called to testify. Coy said McAuliffe wanted to spare them the potentially “exorbitant” cost of hiring their own attorneys. Two of the subpoenaed Cabinet secretaries have stayed on under McAuliffe: Agriculture and Forestry Secretary Todd Haymore and Health and Human Resources Secretary Bill Hazel.

“The governor did not want them to bear that burden,” Coy said.

McAuliffe’s move opened Herring up to criticism that he had acted rashly, and politically, when he dismissed the lawyers. “One of the greatest hazards as a lawyer is acting out of haste,” said Sen. Mark D. Obenshain (R-Harrisonburg), who narrowly lost the attorney general’s race to Herring.

Herring spokesman Michael Kelly stood by the original decision to drop the lawyers — and late Wednesday said Herring did not know about the governor’s move beforehand, even though Coy said the attorney general had been consulted.

“After looking closely at the law and the circumstances, Attorney General Herring moved to protect taxpayers and ensure the office was working only within its statutory authority,” Kelly said. “The attorney general’s office has very limited authority to provide legal services in criminal matters. The governor has more latitude to engage those kinds of services.”

Five days after taking office, Herring dismissed two firms: Eckert Seamans, which had been hired to represent McDonnell (R) in his official capacity as governor, and Baker & McKenzie, which was representing his staff.

Herring’s predecessor, Ken Cuccinelli II (R), had hired the firms after determining that he had a conflict of interest. The arrangement became controversial because the firms charged taxpayers a lot of money, $785,000 at the time of their dismissal.

There was also criticism because of the appearance that the firm working for the governor might be aiding in his personal defense rather than simply representing him in his official capacity. Eckert Seamans has not been rehired to represent McDonnell, who has a personal defense counsel paid for by a legal defense fund.

The most recent Baker & McKenzie bills released by the state date to November. Coy said he had no information on their charges in December and January or since their rehiring in March.

Rosalind S. Helderman contributed to this report.