RICHMOND, Va. (AP) — A Democratic tidal wave on Election Day in Virginia three weeks ago has left chaos in its wake, with control of the House of Delegates still undecided and no end in sight to the dispute.

Lawsuits, threats and recriminations are flying as the state wrestles with the tricky question of what to do about the 147 voters in and around a crucial district who were given the wrong ballots.

Depending on what happens to that seat and two others, the 100-member House could fall into Democratic hands for the first time in nearly 20 years or find itself evenly divided and perhaps paralyzed.

It's the Virginia version of the "hanging chad" debacle in Florida that threw the 2000 presidential election into confusion. As in that race, it could take several weeks and the intervention of the courts to determine the outcome.

"I've never seen anything like this," said Virginia Board of Elections Chairman James Alcorn.

The Republicans have gone from a commanding 66-34 majority in the House to an apparent 51-49 lead, with GOP candidates clinging to extraordinarily slim leads in three districts. (There were no elections this year for the state Senate, where Republicans hold a majority by just one seat.)

In one of the hard-fought House districts, the 28th, in the Fredericksburg area about 50 miles south of Washington, Republican Bob Thomas leads Democrat Joshua Cole by just 82 votes. But the state elections commission recently found 147 voters in the district and neighboring ones cast their ballots in the wrong district.

Exactly why they were assigned to the wrong districts is unclear, as the registrar responsible died in April. But Elections Commissioner Edgardo Cortes said it was probably an error by a registrar working with limited resources and antiquated equipment. He said Virginia has underfunded its election offices around the state and similar problems could exist in other districts.

Virginia's off-year elections were closely watched as a potential referendum on President Donald Trump and a preview of the midterm elections. The Democrats rode a wave of anti-Trump voter sentiment to capture all three statewide offices and exceed all but the most optimistic predictions in the state House.

Few expected the 28th to be close. Outgoing GOP House Speaker Bill Howell often faced no challenger in the district and won in 2015 by 20 points.

On Monday, the Virginia Board of Elections voted to certify the results of the 28th, after the Democrats failed to get a federal court to delay action. Alcorn said that state law left the board with little choice but that there were clear irregularities in the district and that he hopes the courts step in.

Democratic House Leader David Toscano said his party is weighing its options. The Democrats have already filed a lawsuit in federal court in hopes of persuading a judge to order a new election in the 28th.

"This is really uncharted territory, but I think the logic we have is very strong," Toscano said.

GOP House Leader Kirk Cox, who is slated to be speaker should the Republicans maintain their majority, said he was disappointed the board held up certification by a week.

"Dragging this process out has only prolonged the important work that remains to be done by both sides" in preparation for the upcoming session, he said.

The Democrats have until later this week to file requests for recounts in two other close races: in Newport News, where Republican David Yancey has a 10-vote lead, and in northern Virginia, where GOP candidate Tim Hugo is ahead by 106 votes.

If the final result is a 50-50 split in the House, things could get even messier, and the two parties may have to compromise just to elect a speaker and assign committee chairmanships.

The last time the House was evenly divided was 20 years ago, when the parties reached a power-sharing agreement. But if no agreement can be reached, prolonged chaos could ensue.