WASHINGTON — While President Joe Biden attended the United Nations summit on climate change in Glasgow, Scotland, television cameras caught him appearing to doze while listening to speeches, a reminder of how exhausting overseas travel can be.

But if he was hoping for a reprieve after returning to the White House on Wednesday, he’ll be disappointed. Waiting for Biden is a storm of political challenges that threaten his agenda on Capitol Hill and that have sent Democrats into spasms of fear over their prospects in the upcoming midterm election.

Terry McAuliffe, the Democratic candidate for governor in Virginia, was defeated in a state that his party had considered safe ground. He trailed Glenn Youngkin, the Republican, by a little more than two percentage points in Tuesday’s election. Priorities USA, a leading Democratic super PAC, called the outcome “a warning for all Democrats.”

The party found little solace in New Jersey, where Gov. Phil Murphy was locked in a much tighter race than expected with his Republican opponent, Jack Ciattarelli. The two candidates were nearly evenly split as votes were being counted into the night.

The Virginia campaign in particular was considered a bellwether as lawmakers sharpen talking points for the upcoming midterm and consider trillions of dollars of Biden’s proposals on Capitol Hill. Youngkin flexed muscle not only in conservative rural counties but also made significant inroads among suburban voters who were key to Democrats’ recent gains in the state.

“This was not supposed to be such a close race,” said Mark Rozell, dean of the Schar School of Policy and Government at George Mason University. “Democrats were supposed to easily win in a state that has trended increasingly blue.”

McAuliffe, a former governor and a fixture in Democratic politics, had aggressively worked to tie Youngkin to former President Trump in hopes of juicing turnout among his supporters. But even with high turnout, Democrats were unable to ward off a Youngkin win, suggesting that strategy may not be effective with the same demographic that provided critical backing to Democrats last year.

“Youngkin winning these college-educated white voters who are skeptical of Trump indicates Biden’s approval is likely slipping with these same types of groups in key battleground metropolitan areas like Atlanta,” said J. Miles Coleman, a political analyst at the University of Virginia’s Center for Politics.

Biden projected confidence Tuesday during a news conference in Glasgow before returning to Washington, leaning into the microphones and saying, “We’re going to win,” when asked about the Virginia race.

He also suggested the campaign shouldn’t be considered a reflection on his legislative proposals, which have been trapped in congressional quicksand as progressive and moderate lawmakers debate what should be included and how to pay for it. House Democrats hope to break the logjam with a series of votes this week, and another delay could undermine momentum for reaching a deal.

As Biden presses forward, he’ll be drawing on dwindling reserves of political goodwill, with public opinion surveys showing the president becoming increasingly unpopular.

An average of polls compiled by the political website FiveThirtyEight shows Biden’s approval rating sinking badly in August, a drop that corresponded with the chaotic withdrawal from Afghanistan. Since then, the gap has widened, with 50.7% expressing disapproval and 43% supporting his job performance.

Biden brushed off the grim numbers during an earlier news conference in Rome, where he attended the G-20 forum for world leaders.

“The polls are going to go up and down and up and down,” he said Sunday. “They were high early, then they got medium, then they went back up, and now they’re low.”

Biden is quick to remind reporters that he’s been written off before. Pundits read his presidential campaign its last rites before he captured the Democratic nomination last year, and they’re constantly checking for a pulse on his legislative agenda.

“You’ve all believed it wouldn’t happen from the very beginning, the moment I announced it, and you always seem amazed when it’s alive again,” he said. “Well, you may turn out to be right — maybe it won’t work. But I believe we’ll see by the end of next week, at home, that it’s passed.”

Sean Clegg, a Democratic strategist based in San Francisco, said the outcome in Virginia puts pressure on Biden to contain the fallout from his flagging approval numbers.

“If it’s a portent to 2022 — you can debate that,” Clegg said. “But [the Virginia election] is clearly a reflection of a dynamic that’s going on right now in the party and with the president, and we need to correct it if we want to have any success.”

Biden’s agenda is split between two pieces of legislation. One is geared toward investing in infrastructure such as roads and bridges, and the other is focused on fighting climate change and expanding the social safety net. The president released a revised framework on the latter legislation last week before leaving for Europe in hopes of prodding negotiations toward their conclusion.

House Democrats aim to hold votes on both measures in the coming days. However, it’s unclear if there will be enough support from progressives who are concerned that centrist Sens. Joe Manchin III (D-W.Va.) and Kyrsten Sinema (D-Ariz.) will oppose the social spending bill.

Clegg said that what ultimately cost McAuliffe the race is the “feeling that, OK, we gave you all the reins of power and you’re not delivering anything except a picture of internal, internecine squabbling.”

“All the forces that have been impeding getting visible progress done in the House and Senate need to cut it out,” Clegg said.

Chris Stirewalt, the former political editor of Fox News, predicted that the immediate fallout among Democrats would be “anger at the Congressional Progressive Caucus, and Manchin and Sinema” for the protracted negotiations over Biden’s legislative agenda.”

“The decision to blockade [the] bipartisan infrastructure package was a substantial part of McAuliffe’s problems,” Stirewalt said.

The onus on Biden is to unify the warring flanks of his party, especially since Trump is not in office to bring them together in opposition. Otherwise, the president risks continuing to look “weak and unable to deliver,” said Stirewalt, now a senior fellow at the American Enterprise Institute, a conservative think tank.

Biden was repeatedly asked about the grinding debate over his proposals while in Europe, especially as he promised world leaders that the U.S. would take decisive action on climate change.

During his news conference in Rome, the president said he believed he could get it done.

“It’s going to pass, in my view,” he said. “But we’ll see. We’ll see.”