Democrat Mark Herring, left, and Republican Mark Obenshain participate in a campaign debate on Oct. 2 in Leesburg. (Jahi Chikwendiu/The Washington Post)

Republican state Sen. Mark D. Obenshain will formally ask for a recount in the historically tight race for Virginia attorney general, leaving the final outcome still unclear three weeks after Election Day.

The State Board of Elections certified the results of the contest Monday, with Sen. Mark R. Herring (D-Loudoun) declared the winner by 165 votes out of more than 2.2 million cast. That result — the closest statewide race in modern Virginia history — is well within the margin for the loser to request a recount paid for by localities rather than the candidate.

The Obenshain team announced Tuesday afternoon that it would do just that. Two members of his legal team, Ashley L. Taylor Jr. and Stephen C. Piepgrass, will hold a conference call with the news media at 10 a.m. Wednesday.

Herring has been proceeding as though he expects to serve as the next attorney general. He previously named a transition team, and on Tuesday he announced the five co-chairmen of his inaugural committee. The Democrat’s chief attorney, Marc Elias, has said it is very unlikely that a recount would overturn the result.

“It is within Senator Obenshain’s right to pursue electoral victory to an ultimate conclusion beyond the original count, canvass and certification,” Herring said in a campaign statement Tuesday. “His tactics, however, will not impede our efforts to build the finest team to serve all Virginians in the Office of Attorney General or prepare for the 2014 legislative session.”

But Obenshain, who is from Harrisonburg, has also named a transition team and has stressed that the race is so close that a recount could well make the difference. Obenshain’s campaign noted Monday that there have been four statewide elections across the country since 2000 with margins under 300 votes, and three were reversed by recounts.

Pat Mullins, the chairman of the Republican Party of Virginia, said Obenshain had “made the right decision.”

“Recounting a race this close is simply the prudent thing to do,” Mullins said. “Virginians like a quick resolution to our elections. I know I certainly do. But we must take the time to be sure that each and every legitimate vote is counted. Virginians deserve no less.”

In a radio interview Tuesday, Gov. Robert F. McDonnell (R) said he would “absolutely” ask for a recount if he were in Obenshain’s shoes.

“I feel for both of the candidates,” McDonnell said. “Here they are, they’ve slugged it out for two years, and it ain’t over. . . . I think both Mark and Mark are going to have a stressful Thanksgiving.”

The last statewide recount in Virginia occurred in the 2005 attorney general race, when then­Delegate McDonnell beat Sen. R. Creigh Deeds (D-Bath) by 360 votes. The result that year wasn’t certified until Dec. 21.

“Normally these procedures take a few weeks,” said Stephen Farnsworth, a political science professor at the University of Mary Washington. “You want to do it right . . . so the recount will be done with a carefulness that will require more than just a few days.”

Under state law — which has changed since 2005 — a special recount court will be formed, led by the chief judge of the Circuit Court in Richmond. The court will hear disputes and challenges raised by the two campaigns. Every ballot that can be recounted by hand will be, and those counted by optical scan machines will be run through the machines again.

Republicans have already raised questions about the way ballots were tallied in Fairfax County, where people who cast provisional ballots were given more time than in other jurisdictions to appear in person to argue that their votes should count.

Charles E. Judd, the chairman of the State Board of Elections, cited that point Monday when he said he had voted to certify the results “with question.” But Judd also said he did not think the Fairfax issue would change the outcome of the election, and the secretary of the Fairfax Electoral Board has said the board acted according to state law.

Virginia law also includes a provision that would allow the loser after a recount to contest the result in an unusual joint session of the state House of Delegates and Senate, where Republicans would have a wide partisan advantage. Obenshain’s campaign has not said whether he would consider that route.

McDonnell said Tuesday that he thought the bar would be high for such a contest.

“You’d have to make the case that there was something so unjust about the conduct of the election that the only fair remedy would be for the legislature to vote,” McDonnell said. “I think we’re a long way from that determination.”

Laura Vozzella contributed to this report.