Mr. Yancey’s extraordinary reversal of fortune came a day after a recount erased a 10-vote lead he held on Election Day. His lawyer said that was the first time in Virginia that an election result had been changed in a recount. Republicans had even congratulated Ms. Simonds and pledged to share power in bipartisan fashion. Ms. Simonds took a victory lap early Wednesday on MSNBC’s “Morning Joe.”

A lawyer for the Virginia House Democratic caucus, Marc Elias, said that the local court’s decision about the ballot was wrong and that he was assessing legal options. “The Republicans themselves had affirmed that this result was accurate yesterday before changing their minds today,” Mr. Elias said in a statement. “After conceding this seat and their majority, they are now desperately trying to claw both back.”

Ms. Simonds’s representative argued before the judges that the disputed ballot should not be counted because it was an example of an “overvote,” when multiple candidates for the same race are chosen. However, the Virginia Department of Elections, in a guide to hand-counting ballots, appears to address the issue, showing an example in which a voter marks two candidates but clarifies the intention using “an additional mark or marks that appear to indicate support.” In that case, the guide says, “the ballot shall be counted.”

Tied votes, which are extremely rare, have occasionally been broken around the country by coin tosses or the like. A City Council race in Idaho was decided by a coin toss in November, only to have the results reversed after a recount. A survey of states in 2014 by The Washington Post found that 35 had provisions for breaking ties by means of chance, though often the particulars are vague. A decade ago, Connecticut repealed its coin-toss rule in favor of deciding tied races through the Legislature or by a runoff — in other words, a do-over.

The closeness of the Virginia House race was part of a Democratic surge that flipped 15 other Republican-held House seats to Democrats, who also held onto the governor’s office. Mr. Yancey had won the House district two years ago by drubbing Ms. Simonds, 57 to 42 percent.

That their rematch was so close was seen as another example in Virginia of a rebuke to President Trump. It also was a textbook lesson, in an age of fights over access to the voting booth, that every ballot matters.

Willard Hoskins, 78, a Republican-leaning voter in the district, said he had voted for Mr. Yancey, never expecting how close the race would become. “If the mood of the people shifts, then watch out,” Mr. Hoskins said.