As Joe Biden amassed small but stable leads in critical states that edged him closer on Wednesday to winning the presidency, President Trump and Republicans threatened legal challenges as they sought to shift the battle for the White House from the ballot box to the courts.

Hours after President Trump prematurely declared victory, his campaign made baseless claims of voter fraud, filed for a recount in one state and tried to stop the counting of ballots in others where the president was behind.

But as Trump’s antics and rhetoric grew more aggressive over the course of the day, Biden’s electoral position only strengthened — and states including Michigan and Wisconsin fell into his column. The former vice president has secured 253 electoral votes, with multiple paths to the required 270.

Biden delivered brief remarks in Wilmington, Del., on Wednesday, sounding an upbeat tone and offering a conciliatory message to a nation whose deep divisions and partisan strife were laid bare by the election results.

“It’s clear that we’re winning enough states to reach 270 electoral votes needed to win the presidency,” Biden said Wednesday afternoon with his running mate, Sen. Kamala D. Harris (D-Calif.), by his side. “I’m not here to declare that we’ve won. But I am here to report, when the count is finished, we believe we will be the winners.”

He also encouraged Americans “to put the harsh rhetoric of the campaign behind us” and “to lower the temperature, to see each other again.”

Trump, who remained in private throughout the day, had a starkly different message. He tweeted his displeasure at the election results, made unsubstantiated claims of vote rigging and sent a text message to supporters calling on them to donate to his campaign to “FIGHT BACK.”

The source of Biden’s confidence and Trump’s angst: late-counted mail-in ballots in urban centers such as Milwaukee and Detroit that swung Wisconsin and Michigan to the former vice president, putting him on a clear path toward victory.

On Wednesday afternoon, with a lead of 49.4 percent to Trump’s 48.8 percent, Biden was projected as the winner in Wisconsin by Edison Research. Election officials in the state said just about all votes had been counted.

Biden later was projected by Edison Research to win Michigan, after surging to a slim lead in the state as ballots were tallied Wednesday. Trump won Michigan and Wisconsin in 2016 en route to his surprise victory.

Biden’s victories in Wisconsin and Michigan provided Democrats with cautious optimism hours after they bemoaned their worse-than-expected showing Tuesday night. Despite setbacks in House and Senate races, some Democrats took solace from the fact that they were in striking distance of ousting Trump from the White House.

But even as Biden’s national vote count surpassed a record 70 million, the national race was far from the broad and expansive repudiation of Trump that Democrats had hoped for as they sought to unseat a divisive president amid a deadly pandemic that has killed more than 233,000 Americans. Trump won at least 4 million more votes than he did in 2016 and remained competitive in several swing states where the results were too close to call Wednesday — preventing Democrats from being able to declare victory nearly 24 hours after polls began closing on the East Coast.

Trump campaign officials said they had requested a recount of Wisconsin’s ballots and were moving to block the continued count in Michigan until their observers could gain access to tabulating sites. The campaign also filed a lawsuit alleging voter irregularities in Georgia, where Trump’s lead over Biden narrowed considerably Wednesday.

Trump maintained leads in Pennsylvania, Georgia and North Carolina — but all three shrank as votes were counted. Arizona and Nevada, where Biden was leading, remained too close to call, with thousands of votes left to be tallied. Biden could capture the presidency by holding on to his leads in Arizona and Nevada — though it could take days for a final tally to be available.

Amid the uncertainty, both campaigns sought to project confidence and ready their lawyers for a potentially protracted legal battle.

Both campaigns predicted victory during simultaneous telephone news briefings Wednesday, and in a separate briefing for supporters, the Trump campaign previewed a slate of legal challenges that the president had touted before the voting ended.

“We are in recount territory in Wisconsin, in Michigan, the same way,” deputy campaign manager Justin Clark said, according to a recording of the call obtained by The Washington Post. “I believe we will be lodging legal challenges in both of those places because there is some . . . to counteract any funny business going on in both of those places.”

“You will see more litigation today, likely,” Clark said about Pennsylvania, adding that a challenge could also take place in closely contested North Carolina.

“We have a fully staffed, fully operational team,” he said.

Trump’s personal lawyer Rudolph W. Giuliani held a news conference in Philadelphia and claimed without evidence that more than 125,000 ballots in the city should be disqualified because poll watchers were not able to see them being tallied. While providing no specific evidence, Trump’s campaign manager told reporters Wednesday that the president had prevailed in Pennsylvania. In a tweet, Trump said he won Pennsylvania and asserted “we hereby claim the State of Michigan.”

It was one of several presidential tweets flagged by Twitter on Wednesday as potential electoral misinformation.

Democrats saw Trump’s late, flailing attempts to discredit or stop the vote count as a sign that Republicans had lost the White House.

Still, Tuesday’s election was a sober moment for Democrats, who had hoped to run up the score on Trump to avoid precisely the challenges that Republicans announced Wednesday. Biden had campaigned as a healer, arguing that the president has mismanaged the coronavirus pandemic and cleaved the country with caustic rhetoric about racial minorities, immigrants and “elites” he claims are bent on destroying him. But Biden’s narrow lead showed the ingrained political camps into which Americans have divided.

A protracted battle over the legitimate winner of the election could deepen those national fissures. Trump falsely claimed on Wednesday that the changing tallies suggested the votes are suspect.

“Last night I was leading, often solidly, in many key States, in almost all instances Democrat run & controlled,” Trump tweeted shortly after 10 a.m. “Then, one by one, they started to magically disappear as surprise ballot dumps were counted. VERY STRANGE, and the ‘pollsters’ got it completely & historically wrong!”

The ballots being counted overnight and on Wednesday are neither dumps nor a surprise. In almost all cases, they are among the millions cast by Americans who chose to vote early or by mail, rather than in person on Election Day. Election officials commonly take days if not longer to count every ballot.

As the morning dawned, congressional Republicans saw a landscape far more positive than they had been girding to expect. House Democrats appeared on track to secure another two years in the majority. But the party looked set to fall drastically short of its bullish predictions that it would cut deep into Trump country to grow its majority. Party control of the Senate hung in the balance, but Democratic hopes of securing a majority appeared to dwindle.

Trump broke democratic norms by asserting in a White House speech early Wednesday that he had won, despite trailing in the electoral count in states where victories had been projected. He claimed he will ask the Supreme Court to intervene in the election process, saying that voting must stop and falsely claiming that a continuing count of votes already cast would mean the Democrats would be stealing the election. By that time, polls had closed, and no more votes were being cast, only tallied.

“To me, this is a very sad moment, and we will win this. And as far as I’m concerned, we already have,” Trump said in an unprecedented appearance before supporters.

Before his remarks, Trump complained to aides about voter fraud and expressed concerns that the election could be stolen, according to campaign officials who spoke on the condition of anonymity to discuss private conversations.

Trump was upset that Fox News had called Arizona for Biden and told his aides to “get that result changed,” one person familiar with the activities said.

A number of Trump officials, including Jason Miller, Kayleigh McEnany and former adviser Kellyanne Conway, spent considerable time calling Fox News figures. Fox has stood by its projection.

Trump’s written remarks did not include his declaring victory, but he was determined to do so, one administration official said.

The Biden campaign called Trump’s claim of victory “outrageous, unprecedented, and incorrect.”

Senate Majority Leader Mitch McConnell (R-Ky.) struck a more cautious note than Trump did on the race for the White House, saying that the victor remains unclear.

Turnout in Tuesday’s historic vote was on pace to be the highest in more than a century. With the country gripped by the deadly coronavirus, millions of people chose to vote by mail or by other means, contributing to enormous backlogs of ballots, while others voted traditionally on Tuesday.

In 2016, Trump carried Wisconsin over Democrat Hillary Clinton by a margin of 0.8 of a percentage point, adding 10 electoral college votes to his total. He won Michigan’s 16 electoral votes by a margin of 0.2 of a percentage point. The third Democratic state he narrowly flipped was Pennsylvania.

On Wednesday, after Wisconsin and Michigan were projected as Biden victories, Pennsylvania officials labored to count more than 1 million mail-in ballots, including many from the Philadelphia area, where Biden is presumed to hold an edge.

As of 6:45 a.m., Trump held a sizable lead, at least partly because of in-person votes on Election Day, which were cast disproportionately by Republicans.

Trump allies and opponents criticized his pledge to challenge states still counting votes, as well as the president’s false claim that he had won the election. Rep. Adam Kinzinger (R-Ill.), who has voiced opposition to Trump in the past, tweeted at the president to “stop.”

“The votes will be counted and you will either win or lose. And America will accept that. Patience is a virtue,” Kinzinger wrote.

In races for the House and Senate, Trump’s unexpectedly strong performance in some places paid dividends for Republicans: Many had feared a wipeout if down-ballot candidates were dragged down by the president. Even with many races still uncalled, on Wednesday morning it was clear there had been no wipeout.

Among Senate races, Democrat John Hickenlooper unseated incumbent Republican Cory Gardner in Colorado, and Republican Tommy Tuberville defeated incumbent Doug Jones (D) in Alabama. Mark Kelly (D) also appeared on track to win a Republican-held seat in Arizona. Some of the other closely watched races, including in Georgia and North Carolina, remained too close to call.

But Democrats watched their hopes of taking a Senate majority fade, as GOP incumbents held off challengers in Maine, Iowa, Montana and South Carolina. Republicans held a 53-47 Senate majority going into Election Day.

In the House, Democrats were projected to maintain control. But their hopes of expanding that majority were dashed. Instead, their margin seemed in danger of shrinking, as Republicans flipped Democratic-held seats in South Florida and Minnesota.

The election took place amid a once-in-a-century pandemic that has led to more than 9.4 million coronavirus cases in the United States and upended the economy. The number of daily cases has surged across the country, surpassing 100,000 for the first time Wednesday. Public health experts have been warning that the spread could worsen heading into winter.

But Trump — whose handling of the crisis is a top reason he had trailed Biden in the polls for so many months — insisted on the campaign trail that the country is “rounding the curve” on the virus. The president also promised that a vaccine and various therapeutics will soon be widely available, which is more optimistic than the timelines provided by health officials.

Biden wagered that legions of women and minority voters who have recoiled from Trump’s divisive conduct in office would bring an end to his tumultuous presidency. The former vice president offered himself as a healer with the compassion and empathy he said was needed to usher in an era of civility and restore the soul of America.

Biden also sought to make history with Harris as his running mate. A daughter of Jamaican and Indian immigrants, she would be the first female, first Black and first Asian American to hold the country’s No. 2 job.

More than 100 million Americans voted early in person or by mail — by far a record — and overall turnout was expected to exceed the 136.7 million who voted in the 2016 presidential election.

David Fahrenthold, Carol Morello, Josh Dawsey, John Wagner, Felicia Sonmez, Griff Witte, Annie Linskey, Susan Levine, Amy Gardner and Scott Clement contributed to this report.