Democrat Joe Biden held a narrow lead in Wisconsin on Wednesday after officials completed their vote count in the pivotal state, a major boost in his quest to win the US presidency from Donald Trump despite the Republican incumbent’s false claim of victory and unsubstantiated allegations of electoral fraud. Biden also led in another critical Midwestern battleground state – Michigan – as he and Trump raced to get to the 270 electoral votes in the state-by-state Electoral College needed to win the White House. Trump won Wisconsin and Michigan in his 2016 election victory. Trump’s campaign said on Wednesday afternoon it had filed a lawsuit seeking to halt vote counting in Michigan and asserting that it had not been given enough access to counting sites to observe the opening of ballots. Biden was ahead by 45,000 votes out of more than 5 million ballots in Michigan. Wisconsin officials finished their tally at around midday after an all-night effort, showing Biden with a lead of just over 20,000 votes, or 0.6%, according to Edison Research. The Trump campaign immediately said it would seek a recount, which is permitted under state law when the margin is below 1%. A Biden victory in Wisconsin would significantly narrow Trump’s path to a second four-year term, though the outcome remained in doubt with Michigan and other closely contested states including Pennsylvania, Arizona, Nevada, Georgia and North Carolina still counting votes. Trump led in the two Southern states, Georgia and North Carolina, as well as in Pennsylvania, where more than 1 million ballots were yet to be processed. But if Trump loses Wisconsin, he would have to win all three as well as either Arizona or Nevada, where Biden was leading in the latest vote counts. At the moment, not including Wisconsin, Biden leads Trump 248 to 214 in Electoral College votes, which are largely based on a state’s population. In duelling conference calls with reporters earlier on Wednesday, officials from each campaign insisted their candidate would prevail. “If we count all legal ballots, we win,” Trump campaign manager Bill Stepien said, potentially setting the stage for post-election litigation over the counting of mail-in ballots. Biden campaign manager Jennifer O’Malley Dillon told reporters the former vice president was on track to win the election, while senior legal adviser Bob Bauer said there were no grounds for Trump to invalidate lawfully cast ballots. “We’re going to defend this vote, the vote by which Joe Biden has been elected to the presidency,” said Bauer, adding that the campaign’s legal team was prepared for any challenge. Trump continued to make baseless attacks on the vote-counting process on Twitter on Wednesday, hours after he appeared at the White House and declared victory in an election that was far from decided. Both Facebook and Twitter flagged multiple posts from the president for promoting misleading claims. “We were getting ready to win this election. Frankly, we did win this election,” Trump said before launching an extraordinary attack on the electoral process by a sitting president. “This is a major fraud on our nation. We want the law to be used in a proper manner. So we’ll be going to the US Supreme Court. We want all voting to stop.” Trump provided no evidence to back up his claim of fraud and did not explain how he would fight the results at the Supreme Court, which does not hear direct challenges. In the nationwide popular vote, Biden on Wednesday was comfortably ahead of Trump. Trump won the 2016 election over Democrat Hillary Clinton after winning crucial battleground states even though she drew about 3 million more votes nationwide. Biden’s hopes of a decisive early victory were dashed on Tuesday evening when Trump won the battlegrounds of Florida, Ohio and Texas. Biden led in Arizona, a battleground state with a high Latino population, which would make him only the second Democratic presidential candidate to win the state in 72 years. Trump won the state in 2016. In Pennsylvania, officials said they were slowly working their way through millions of mail-in ballots, which were seen as likely to benefit Biden. Across the state, there were about twice as many ballots left to count in counties that backed Hillary Clinton in 2016 than in the counties won that year by Trump. In Michigan, where officials said they expected to finish counting by day’s end, Biden was ahead by 30,000 votes out of more than 5 million ballots by midday.