By Thursday morning, President Trump was angry and defiant.

The polls had closed more than a full 24 hours before, and as several key states continued to update their ballot counts, the election increasingly felt like it was slipping away from him and toward Democratic nominee Joe Biden. He wanted to speak.

“STOP THE COUNT,” Trump bellowed on Twitter, a missive he quickly retweeted just over an hour later. “ANY VOTE THAT CAME IN AFTER ELECTION DAY WILL NOT BE COUNTED!” he added.

The only problem: If the vote-counting stopped at that moment, Trump would lose.

Trump’s senior advisers intervened, explaining to the president that he needed to be more precise about just which vote counts he wanted halted. He did not want all of the states to stop counting votes, they added, because that would lead to a Biden victory.

And so, shortly after noon Thursday, Trump blasted out the message he had workshopped with advisers: “STOP THE FRAUD!”

There is no evidence of widespread voting fraud, and Twitter flagged his tweet as “misleading” about the election. But for the president’s purposes, the missive was more helpful to his electoral hopes.

“Trumpworld is going to go down swinging hard,” said Dan Eberhart, a Republican donor.

Those in the president’s orbit had entered Election Day cautiously optimistic. During a midday visit Tuesday to rally staff at campaign headquarters, the president said he had not yet given much consideration to either a victory or concession speech.

“Hopefully, we’ll be only doing one of those two,” he said. “And, you know, winning is easy. Losing is never easy. Not for me, it’s not.”

But by Tuesday night, it became increasingly clear that Trump would deliver neither speech.

Huddled with family members and advisers — including Kellyanne Conway, campaign adviser Corey Lewandowski, Chief of Staff Mark Meadows and former White House press secretary Sarah Sanders, among others — first in the White House residence and then in the Map Room, Trump became increasingly agitated as the evening wore on.

At one point, when Fox News — the cable channel most friendly to the president — called Arizona, which Trump had won in 2016, for Biden, the president implored his team to “get that result changed,” said one person familiar with his exhortations who, like others, spoke on the condition of anonymity to share details of internal discussions. Campaign adviser Jason Miller took to Twitter to complain — “WAY too soon to be calling Arizona,” he wrote — and he, along with Conway, former counselor to the president, Meadows and White House press secretary Kayleigh McEnany, spent considerable time calling allies at Fox News, trying to get them to back off the Arizona decision. Trump and aides continued to privately rail against the network Thursday, officials said.

Though aides had tried to prepare Trump that mail-in ballots would probably favor Biden, he was “genuinely taken aback,” in the words of one campaign adviser, as the votes rolled in for his rival, the former vice president.

Instead of reflecting on whether his rhetoric throughout the campaign demonizing mail-in ballots could have helped cost him the election, the president has taken the results as a vindication on his views of it, advisers said.

“The president’s position is, they are just going to keep finding the ballots until they have enough,” said one adviser who spoke to him Wednesday.

Trump began complaining about voter fraud and the election being stolen, and by the time he appeared in the East Wing around 2 a.m. Wednesday to make remarks, he was determined to declare victory, even though his prepared notes did not say that.

“Frankly, we did win this election,” Trump said in comments that were roundly criticized, including by many allies. Some of those in the room, including Lewandowski and Meadows, did not clap along with others after the impromptu line. Vice President Pence, who struck a different tone early Wednesday onstage, made no appearances later Wednesday or Thursday, though Thursday night he did tweet, “I Stand With President @realDonaldTrump. We must count every LEGAL vote.”

The mood among Trump allies remained both combative and hopeful for much of Wednesday, with advisers carefully monitoring several states — including Arizona and Georgia — that they thought could still break Trump’s way, and grasping at the notion that the president could “catch lightning in a bottle again,” a senior administration official said.

In some ways, the chaos and drama was its own version of normalcy for those who have worked around Trump, this person added. “One thing people forget, in general, is that for decades, long before the presidency, his whole life was a crisis and he thrived in that environment,” the official said. “It’d be boring if he just got blown out or won big. That would be very un-Trumpian for there not to be some calamity involved.”

By Wednesday evening, however, Trump had begun telling allies he believed he could lose — but only because the election was being “stolen from him,” a campaign official said. And when he woke up Thursday, he was angry again and eager to take a more defiant tone, advisers said.

The president was eager to speak publicly Thursday about the election — arguing that his rightful victory was being stolen, and that states were conspiring against him. But again, allies and advisers counseled caution, trying to assuage Trump by outlining their aggressive plan to fight and urging him to keep a low profile.

But on Thursday evening, the president appeared in front of reporters at the White House around 6:45, seeming subdued and deflated, and made unproven claims about voter fraud and vowing to continue the fight through legal channels.

He mocked mail-in ballots and polling from the news media and said, falsely, that states were making up ballots to cost him the election. He made a series of other unsubstantiated allegations against democratic elections.

At one point, Trump said states that counted the votes were behaving in a corrupt manner — while Arizona needed to count the ballots so he could win. He walked away without taking questions.

A senior campaign official said Thursday night’s appearance was the kind of news conference they wanted to avoid.

Trump had spent much of the day Thursday ensconced in the Oval Office, watching television coverage of the election and meeting with various advisers, a senior administration official said.

Top campaign staff — including campaign manager Bill Stepien and deputy campaign manager Justin Clark — updated the president throughout the day on their efforts to help Trump wrest control of the election through legal challenges, and also briefed his family and other senior advisers.

The president told advisers he believed he would win, and polled aides and allies all day on whether he should appear publicly, as he was eager to do. He worked on a statement with his press office taking credit for Republican gains in the House and for Republican victories in the Senate — and his standing among minority voters.

“President Trump defied all expectations in Congressional and Senate races, bringing great victories,” said Judd Deere, a deputy press secretary. He did not mention the presidential race tally.

On a call with campaign surrogates, a Trump campaign spokesman confidently declared, “We will be able to declare absolutely victory Friday afternoon when Arizona flips.” And the campaign also blasted out a fully capitalized statement from the president: “IF YOU COUNT THE LEGAL VOTES, I EASILY WIN THE ELECTION! IF YOU COUNT THE ILLEGAL AND LATE VOTES, THEY CAN STEAL THE ELECTION FROM US!”

Campaign officials also tried to show pugilism with donors and surrogates, asking for money and encouraging allies to go on television and defend the president — saying he would be declared the victor by Friday.

But privately, several people close to the campaign said the mood began to darken. In one call, Hogan Gidley, a campaign press secretary, promised that Trump would be declared the victor on Friday. “It was kind of laughable,” said a person on the call.

Some in the president’s orbit, including his family, grew incensed that more Republicans were not echoing his comments and publicly fighting for his reelection. Trump’s oldest son, Donald Trump Jr., on Twitter called for “2024 GOP hopefuls” to forcefully speak out on his father’s behalf — a not-so-vague allusion to the influence the president and his family are likely to hold over the Republican Party for years to come. Trump’s son Eric also took to Twitter to lament, “Where is the GOP?! Our voters will never forget . . .”

Some of the efforts the campaign did manage to mobilize had an amateurish feel. In North Las Vegas, Richard Grenell, the former acting director of national intelligence, and Matt Schlapp, chairman of the American Conservative Union, held a news conference to draw attention to what they claimed were illegal votes. But Grenell refused to give his name to local news reporters, who did not recognize who he was, and then declined to answer follow-up questions asking him to provide specific evidence for his claims.

Two senior campaign officials said they expected a public-relations effort as well as a legal operation over voter fraud to continue for days, if not weeks. They began asking donors to give large checks for the effort, according to two people familiar with the effort.

Though they remained bullish that he might ultimately eke out a win in Arizona, they privately conceded that they thought he would probably lose Pennsylvania.

“The ballgame is not over but it’s fading away from Trump a lot,” Eberhart said. “It could be a fitting end to Trump. He was so litigious for his business career, and he might go down in a torrent of lawsuits.”