(The latest: Court tosses out one-vote victory in recount that had briefly ended a Republican majority in Virginia)

The balance of power in Virginia's legislature turned on a single vote in a recount Tuesday that flipped a seat in the House of Delegates from Republican to Democratic, leaving control of the lower chamber evenly split.

The outcome, which reverberated across Virginia, ends 17 years of GOP control of the House and forces Republicans into a rare episode of power sharing with Democrats that will refashion the political landscape in Richmond.

It was the culmination of last month’s Democratic wave that had diminished Republican power in purple Virginia.

Democrat Shelly Simonds emerged from the recount as the apparent winner in the 94th House District, seizing the seat from Republican David Yancey. A three-judge panel still must certify the results, an event scheduled for Wednesday.

Of the 23,215 votes cast in the district on Election Day, Yancey held a lead of just 10 votes going into Tuesday’s recount.

But five hours later, after a painstaking counting overseen by local elections officials and the clerk of court, Yancey’s lead narrowed — and then reversed.

The final tally: 11,608 for Simonds to 11,607 for Yancey.

“I knew it was going to be a roller-coaster ride, and the counts were going to change and votes were going to shift around. But I had faith in the system and final outcome,” said Simonds, who stayed off Twitter to avoid anxiety. “This is part of a huge wave election in Virginia where voters came out in record numbers to force a change in Virginia, and I’m really proud to be part of that change.”

Power sharing in the House of Delegates is an awkward exercise; the last such arrangement was in 1998. Committee chairs have to be negotiated, as does the person who will serve as speaker. With the parties split 50-50, there is no mechanism to break ties, and any legislation short of 51 votes does not advance.

Republicans hold a slight 21-to-19 edge in the state Senate, but with a Democratic lieutenant governor to break ties and a Democratic governor with veto power, Republicans may be forced to advance a more bipartisan agenda.

It’s a dramatic shift that caught even top Democrats by surprise. Republicans have controlled the 100-seat House since 2000; even outgoing Gov. Terry McAuliffe (D), a cheerleader for his party, had thought the Republican edge was insurmountable.

But Democrats fired up by the election of Donald Trump as president turned out in big numbers on Election Day and ran as candidates in districts that hadn’t seen Democratic challengers in years.

That wave hit a new high mark with Tuesday’s recount.

“I don’t even live in the district but I am so excited, I can’t believe it,” said Susan Mariner, a Democrat who had come from Virginia Beach just to see the recount.

Even election officials who had spent the day keeping order seemed rattled by the fact that such a momentous race could be settled in such dramatic fashion.

The adage about how every vote counts is true, said Newport News Electoral Board Chairman Sean Devlin as he announced the official result. “Please make sure to stress that,” he said to the gathered reporters.

Both sides agreed that the recount went smoothly, but as the day wore on, the humdrum trickle of a vote here and a vote there began to build to high tension.

Volunteers had arrived at the Newport News city office building as early as 7:30 a.m. A conference room was outfitted with coffee, little buckets of candy and two massive ballot-scanning machines that the city rented for $15,000.

Teams of recount officials sat at four tables in the center of the room with lawyers, the news media and other onlookers kept along two walls. Each table featured two paid election officials — one selected by each party — and two volunteer observers, also one for each party.

Workers fed paper ballots into the machines one precinct at a time. Every time the machine couldn’t read a vote, it spit out the ballot. Those ballots were examined to determine whether they carried a valid vote.

Of the 23 precincts, plus absentee and provisional ballots, there were only about 200 to 250 ballots that had to be examined by hand, Devlin said. Hour by hour, as each precinct was completed, workers posted the results on a whiteboard. For much of the day, the result was either “no change” or “Simonds +1” next to one precinct after another.

Reporters and observers squinted to read the board and calculate what was happening to the total. Just when it seemed Simonds was eating away Yancey’s 10-vote margin, the Republican picked up a handful of votes to hold her off.

Attorneys for both sides, seated next to each other, were loose and joking in the morning.

But after a lunch break, the mood began to turn. Yancey stopped picking up votes — or when he did, Simonds matched him. With only three precincts left to count, Simonds had picked up 10 votes and Yancey had picked up four, preserving his lead.

Then Simonds picked up a few more. With one precinct to go, they appeared to be even.

“Anybody know what happens if it’s a tie?” one of the volunteers called out.

“It goes to the General Assembly,” one lawyer said.

In fact, in the event of a tied recount, Virginia law says the state Board of Elections chooses the winner by “determination by lot” — essentially, a coin toss.

By this time, he and the other lawyers were standing, pacing, talking in urgent tones into their cellphones. A shouting match erupted over whether the volunteer observers could talk to the election officials, and Devlin told the quarreling lawyers to quiet down or go outside.

At 3 p.m., Devlin told all the officials and observers to take their seats. The room had gone nearly silent, with all but one precinct in and Simonds showing a one-vote lead. Workers brought in a single box of absentee votes, then — with the whole room straining to see whether the whiteboard result would change — city Registrar Vicki Lewis took the paperwork into a back room to go over the totals and check the math.

Twitter was in a frenzy, but the results still weren’t final. At some point, word went around that the provisional ballots had changed nothing, and Simonds’s one-vote margin seemed to stand. The attorneys for Yancey edged outside with their phones.

By 3:20 p.m. Devlin announced the official results.

The process “appeared good,” said Stephen Klute, a volunteer for Yancey who was an official recount observer. He said he accepted the outcome. “Got to,” Klute said. “It’s the American way. The system works. So be it.”

Simonds had been waiting outside as the recount wound down and said she wasn’t going to celebrate until she had confirmation from the registrar.

She remembered how a Democrat named Jim Scott prevailed in a recount in 1991 to turn a 17-vote loss into a one-vote win — earning the nickname “Landslide Jim.”

“I may become Landslide Shelly,” she said. “As long as they call me delegate, I’m okay with it.”

Yancey, who was in Richmond at a committee hearing, can contest the results of the election with the legislature, a step that veteran lawmakers last recall happening in 1979. But GOP officials said that seems unlikely.

“We congratulate Delegate-elect Simonds and welcome her to this historic body. We also thank Delegate David Yancey for his distinguished service,” House Majority Leader M. Kirkland Cox (Colonial Heights) and other Republican leaders said in an email.

“The responsibilities of the House of Delegates as an institution transcend party labels, and our obligations to govern this Commonwealth remain,” the GOP leaders said. “We stand ready to establish a bipartisan framework under which the House can operate efficiently and effectively over the next two years.”

The House Republican statement dropped the “Speaker-designate” title normally provided to Cox, whom Republicans chose to lead them had they kept their majority. A GOP official, speaking on the condition of anonymity because of the sensitivity of the matter, said Republicans weren’t quite sure what the process would be for choosing the next speaker.

With the chamber tied, House Clerk G. Paul Nardo, as the only sitting officer of the House, will preside over the chamber until a speaker is elected. The speakership will go to whoever can get to 51 votes first.

Gretchen Heal, Yancey’s campaign manager and spokeswoman, left the recount without speaking to voters and did not immediately return a text message and email seeking comment.

The final makeup of the legislature is not settled. Recounts in two additional races are taking place this week: on Wednesday in Richmond’s District 68, where the Democrat leads by 336 votes, and on Thursday in Fredericksburg’s District 28, where the Republican leads by 82 votes. Democrats are seeking a new election in the latter because more than 100 voters were mistakenly given ballots for the wrong legislative district.

Fenit Nirappil and Laura Vozzella contributed to this report.