Joe Biden appeared closer than ever to winning the presidency late Thursday, as the counting of mail ballots in Pennsylvania had him on the cusp of overtaking President Donald Trump’s lead in the state and securing the Electoral College votes needed for victory.

Biden had other paths to victory Thursday night even without Pennsylvania, as he was holding on to an advantage in Nevada and was also close to erasing Trump’s lead in Georgia. But with the race in Georgia in a dead heat even after almost all votes had been counted, the days-long wait for political resolution looked likely to be decided once and for all by Pennsylvania.

Trump’s lead over Biden in Pennsylvania — once as large as hundreds of thousands of votes — had narrowed to less than 25,000 shortly before midnight Friday. The state reported 175,000 mail ballots left to count — many of them in overwhelmingly Democratic Philadelphia.

“We continue to feel very good about where things stand,” Biden said in remarks from Wilmington late in the afternoon. “We have no doubt that when the count is finished, Senator Harris and I will be declared winners.”

Trump, meanwhile, falsely claimed he had already won at a White House news briefing where he took no questions but repeated the false allegations of election fraud he and his supporters have leveled since Tuesday night. “It’s really destroyed our system,” he said of the prevalence of mail voting in the election. “It’s a corrupt system.”

The nation spent Thursday watching to see whether it would be Pennsylvania or other states — Arizona, Georgia, and North Carolina — that finished counting votes first and decided the election. By 10 p.m., none of those races had been determined — although the Associated Press and Fox News had called Arizona for Biden earlier, a call other news organizations didn’t follow.

Because millions of people used mail ballots due to the coronavirus pandemic, results in states like Pennsylvania have taken days to count. Pennsylvania voters submitted more than 2.6 million mail ballots, which elections officials weren’t permitted by law to begin counting until Election Day.

By late Thursday, Trump remained ahead in North Carolina as his lead was diminishing in Georgia, while Biden remained ahead in Nevada.

”I ask everyone to stay calm," Biden said. “The count is being completed.”

His campaign continued to project confidence, saying in an afternoon briefing that it expected to win Pennsylvania and ultimately the White House.

“Let me be very clear: Our data shows Joe Biden will be the next president of the United States,” Biden campaign manager Jen O’Malley Dillon told reporters. “Donald Trump continues to push a flailing strategy designed to prevent people’s votes from being counted."

O’Malley Dillon said the Biden campaign felt “bullish” about his prospects in Nevada and Georgia, while North Carolina was leaning toward Trump.

Across the state, people of both political parties wanted the wait to end — but Biden supporters were striking a more optimistic tone.

“We’re all so excited,” said Liz McDonald, a critical care dietitian who lives about a block from Biden’s childhood home in Scranton, early Thursday evening. “I’m just waiting for Philadelphia to deliver it for him. How great would that be if Pennsylvania put him over the top?”

About 30 minutes away in Kingston, Luzerne County, Mary Witten was feeling hopeful for the first time “in a long time.”

“It’s been too much hate, too much division. It’s been hard,” said Witten, whose children are mixed-race in a town that is largely white. “I’m ready for the lack of respect to end. I hope it does.”

But Trump supporter Rob Acqusto, 43, a manager for an energy company who is also from Kingston, was watching the returns come in with less excitement.

“I feel terrible,” Acqusto said. “I have not given up hope. I go back and forth, but I’m worried. ... I do fear what Biden will do. ... I think in four years a lot of damage can be done and then maybe Trump can re-run, or Don Jr.”

Trump’s diminishing leads in Pennsylvania and elsewhere were the expected and legitimate result of a partisan divide in mail voting: Republicans voted more in person and Democrats voted more by mail. The in-person votes were counted quickly, creating the temporary illusion of large advantages for Trump before the slower-to-count, Democratic-trending mail ballots were counted.

But Trump leveled numerous baseless claims of fraud at Pennsylvania in particular, as elections officials in the state continued counting mail ballots.

“We were up by nearly 700,000 votes in Pennsylvania,” he said in his evening address, an advantage he had held before millions of ballots were counted. “I won Pennsylvania by a lot.”

On Thursday, his campaign and other Republicans filed legal challenges over the count of ballots in multiple states.

One of those briefly disrupted Philadelphia’s count. Elections officials stopped tallying votes for an hour or two as they scrambled to accommodate a state court order that representatives of the Trump campaign be allowed to more closely monitor the process. A federal judge in Philadelphia on Thursday night dismissed a motion by Trump’s campaign challenging its access to observe the vote-counting in Philadelphia.

Bob Bauer, a senior adviser to the Biden campaign, said the Trump campaign’s lawsuits in Pennsylvania and other states were “meritless” and “part of a broader misinformation campaign” about the integrity of the election.

The likelihood that the vote-counting would stretch into a fourth day came after a day of attacks by the Trump campaign on the counting of legally cast votes, including in Pennsylvania, where some of his supporters gathered outside the Convention Center in Philadelphia, where ballots were being tallied as protesters demonstrated in support of counting every vote.

Pennsylvania Secretary of State Kathy Boockvar said Thursday afternoon that the winner in Pennsylvania “definitely could” be announced later that day. But by Thursday evening, the number of outstanding mail ballots remained larger than the margin separating the candidates.

Philadelphia had the largest number of mail ballots remaining: As of 9:20 p.m, the city had more than 72,000 still to count. Lehigh had more than 15,000, and Bucks more than 13,000 ballots.

Allegheny County had the second-largest number of outstanding ballots, with more than 36,000 left, due to a court settlement over a mailing error that means the county can’t begin processing most of them until after 5 p.m Friday.

At the red, white, and blue-drenched residence in Latrobe known as the Trump House — a Westmoreland County shrine that has become something of a community hub for conservatives in the rural area east of Pittsburgh — only a handful of diehard supporters were stopping in Thursday to lament the state of the race.

“They’re cheating him right now,” said Michael Wujcik, a retired boilermaker. He was speaking with Leslie Rossi, the Republican activist who owns the building and converted the house during the 2016 election. She has used it to work with local Trump fans on building a grassroots campaign, register disaffected Democrats with the Republican Party, and distribute lawn signs and other Trump merchandise.

Rossi expects Trump to pull out a win by exposing electoral corruption. But if Trump loses, Rossi said she doesn’t believe his supporters will engage in mass protests or violence.

“That’s not our style. We’re going to go back to work the next day,” she said.

In downtown Philadelphia, where protests continued outside the Convention Center all day, the “Count Every Vote” demonstration gave way to an hours-long dance party that by evening had drawn hundreds of Biden supporters.

Rowena Dabrey and Elizabeth Grace, both small business owners from North Philadelphia who met on Thursday, joined together in dancing and chanting “count every vote!" around 2 p.m. Four hours later, they were still dancing and contemplating how they’d react if Biden won the state of Pennsylvania.

“This energy is coming from hope," Dabrey, 46, said, later adding, “We really want change."

Inquirer staff writers Jonathan Tamari, Jonathan Lai, Maddie Hanna, Jason Laughlin, Jeremy Roebuck, Anna Orso, Oona Goodin-Smith, and Erin McCarthy contributed to this article, along with the Associated Press.