With Herring up by 163 votes over Obenshain, the Democrat declared himself the victor, while Obenshain refused to concede. He said he will wait for the State Board of Elections to certify the Virginia-wide vote on Nov. 25.

“Voters in Virginia have spoken, their voices have been heard and I am honored to have won their votes and their trust to become Virginia’s next attorney general,” Herring said in a statement. While the vote was close, he said, “Virginians have chosen me to serve as the next attorney general.”

But Obenshain said he wasn’t about to give up in “the closest statewide election in Virginia history.”

“We have seen significant swings in the vote count over the last several days as errors are corrected as a part of the regular canvass process,” he said. “The State Board of Elections will now conduct its own review and we will await their results.”

The seesaw race saw Obenshain emerge election night one week ago with a slight edge over Herring, only to see that lead evaporate over the past several days as election officials certified provisional, or contested, ballots.

The weeklong election drama ended in Fairfax County, Virginia’s largest, as election officials certified provisional ballots. When they were done late Tuesday, Herring had added an additional 160 ballots under his name while Obenshain collected 103.

The additional votes gave Herring an unofficial statewide lead of 1,103,778 votes to Obenshain’s 1,103,615 votes.

The provisional ballots that gave Herring his final unofficial total are cast by voters who came to a polling place without a proper identification or voted in the wrong precinct.

Midnight was the deadline for ballots to be certified by local election boards.

Once the State Board of Elections certifies the vote on Nov. 25, Obenshain must file a petition for a recount within 10 calendar days. Virginia does not provide for an automatic recount.

In his statement, Obenshain did not say if it would seek a recount.

Herring had been chipping away at Obenshain’s lead since Election Day.

On Saturday, Fairfax County tallied 3,000 votes from a district that had undercounted absentee ballots, with two-thirds of the votes going to Herring. Then, an update of voting in Richmond precincts put Herring on top Monday.

Of the 2.2 million ballots cast Nov. 5, Herring and Obsenshain were 0.23 percent of a full percentage point apart before the Fairfax canvass. A candidate who loses by less than one-half of a full percentage point can seek a recount at taxpayer expense. The candidate must foot the bill for a recount if the margin of his loss is between one-half and 1 percent.

The canvass of votes in Fairfax County, the city of Richmond and in other localities work as a recount in a sense, correcting errors that occur in the course of any election, said Robert Roberts, a professor of political science at James Madison University. He said he cannot recall an instance in which the results of a statewide race have been reversed by a recount.

Obenshain and Herring are state senators. Obenshain represents the Harrisonburg area while Herring represents Loudoun County.

Both are seeking to succeed Republican Attorney General Ken Cuccinelli, who lost his bid for governor.

If Herring prevails, it would be the first Democratic sweep of the top of the Virginia ticket in nearly a quarter century. Democrats Terry McAuliffe was elected governor and Ralph Northam lieutenant governor on Nov. 5.