White House Chief of Staff John F. Kelly speaks with White House secretary Madeleine Westerhout as President Trump meets with North Korean defectors in the Oval Office in February. (Jabin Botsford/The Washington Post)

President Trump on Wednesday threatened to order a government shutdown later this month as part of his immigration-related fight for more spending, appearing to contradict the strategy his budget director conveyed to congressional Republicans just hours earlier.

It marked the latest herky-jerky spending confusion from the White House, which has left many lawmakers dizzy and confused as they enter last-minute discussions over how to proceed.

“If it happens, it happens,” Trump told reporters about the possibility of a shutdown during a meeting with congressional leaders. “If it’s about border security, I’m willing to do anything.”

Several hours earlier, White House budget director Mick Mulvaney told congressional Republicans that he was advising Trump not to seek a shutdown later this month and wanted them to pass a spending bill by the Oct. 1 deadline.

House Speaker Paul D. Ryan (R-Wis.) said a shutdown is “not in anyone’s interest, and [Trump] knows that.”

Many government operations are funded only through Sept. 30, giving Congress three weeks to patch together the coalition of lawmakers needed to avoid a partial shutdown. Trump wants Congress to appropriate at least $5 billion for construction of a wall along the U.S.-Mexico border, but congressional leaders have told him they will not be able to marshal enough votes to secure any wall funding by the end of the month.

That has led Trump to threaten to shut down the government repeatedly this year — at least five times since March — but he showed signs this week of backing down, telling the Daily Caller on Tuesday he did not “like the idea of shutdowns.”

But Wednesday afternoon, Trump reverted to his shutdown threat, surrounded by many of the same GOP leaders — including Ryan — who have urged him not to call for a shutdown.

The contrasting comments reflect how Trump has swung back and forth in his government funding strategy, confusing GOP allies as they try to plot an approach.

Returning from the White House meeting, House Majority Whip Steve Scalise (R-La.) sidestepped a reporter’s question about whether he was confident Trump would not shut the government down at month’s end.

“I’m confident that the House is working to make sure we properly fund the military” and send other spending bills to Trump, Scalise said. “The president wants those bills on his desk, by the way.”

But appearing later on Fox News Channel, Senate Majority Leader Mitch McConnell (R-Ky.), who also met with Trump, said there is “no chance of a government shutdown — zero.”

An extended government shutdown would probably send hundreds of thousands of federal workers home without pay and lead to a major disruption in government operations.

“It’s certainly my hope that our country will not once again be brought to the brink of a shutdown while Congress and the administration try to hammer out last-minute deals to keep the lights on,” said Anthony Reardon, president of the National Treasury Employees Union, which represents 150,000 workers.

Trump has seen budget deadlines as his best opportunity for demanding concessions from Democrats, but his threats have failed repeatedly, and GOP leaders have sought to convince him that a shutdown ahead of the midterm elections would be unwise.

The most conservative House Republicans, a bloc that is often very loyal to Trump, appear split on how to proceed, with some still pushing for a fight over the wall now and others suggesting they should wait until later.

There were two brief funding lapses this year, one after Senate Democrats refused to back a spending package in the wake of a new White House immigration policy. But that shutdown was short-lived, and Trump blamed it on Senate Minority Leader Charles E. Schumer (D-N.Y.).

Republicans are trying to marshal a number of priorities through Congress and have expressed concern that a shutdown and polarizing fight over the construction of a wall could splinter the party heading into the midterm elections.

Ryan and McConnell have said they plan to pass as many spending bills as they can before the Sept. 30 deadline and seek a short-term stopgap measure that would keep other agencies open through the midterm elections. That stopgap would include homeland-security funding — punting any fight about wall funding past the election.

“We still are in favor of the wall, we still want to get funding for the wall, but we think the best time to have that discussion is after the election,” McConnell said.

Despite his public comments, Trump was on board with the leadership strategy when it was discussed at Wednesday’s White House meeting, according to a congressional leadership aide briefed on the meeting who requested anonymity to describe the private discussion.

But if Trump demands the wall funding and threatens to veto bills if the funding isn’t given, it could scramble the GOP strategy.

Senate Republicans have spent months trying to methodically advance spending bills in a way that Senate Appropriations Committee Chairman Richard C. Shelby (R-Ala.) has hoped would avert last-minute shutdown threats. Shelby has sought to secure $1.6 billion in wall funding, which is the level initially requested by the White House but far smaller than the $5 billion that Trump has recently suggested he wants and that House Republicans support.

But even though Shelby has tried to make his case to Trump in person that they cannot afford a shutdown fight now, much depends on the president’s political calculus. Trump has made cases in the past both for shutting down the government and avoiding a government shutdown.

Rep. Thomas Massie (R-Ky.) said the message from House leadership behind closed doors earlier Wednesday was “No drama, no drama.”

But Rep. Jim Jordan (R-Ohio), a leader of the conservative House Freedom Caucus, said that voters elected lawmakers to force tough debates and that House Republicans should try to attach funding for a wall this week, giving them time to hold a debate and votes.

“You can’t wait until September 28th or 29th. You’ve got to do it now,” Jordan said. “I think that’s the right approach. That’s one of the fundamental promises we made that we haven’t got done yet.”

Other Republicans are wary of any strategy that could detract from their September and October agendas. Rep. Mark Meadows (R-N.C.), another of the House’s most conservative members and a close Trump ally, said the White House had appeared ready to push any debate over a border wall to 2019.

“In my conversations with the administration, they’re willing to stay engaged on border security measures well beyond a September 30th deadline to fund the government,” he said.

Trump’s comments Wednesday afternoon signaled, however, that he wanted to have the wall fight this month.

Senate Republicans are looking at a rather narrow window to confirm Brett Kavanaugh, Trump’s latest Supreme Court nominee, before the midterms. Republicans also want to pass stopgap spending bills through Congress before Washington becomes too swept up in midterm politics.

Democrats believe they have momentum to seize control of the House in the midterms, which would pose major challenges for Trump’s agenda, particularly the creation of a wall along the Mexico border.

Trump made construction of a border wall one of his top campaign promises, and as recently as last week he vowed Mexico would cover the entire cost.

Mexican officials have repeatedly rejected this.

Trump has sought, though, to have U.S. taxpayers pay for the wall’s construction. He has not specified how he plans to eventually extract the money from Mexico.

He has vacillated on his shutdown strategy again and again.

On July 31, Trump wrote on Twitter, “I don’t care what the political ramifications are, our immigration laws and border security have been a complete and total disaster for decades, and there is no way that the Democrats will allow it to be fixed without a government shutdown.”

Many GOP leaders have said they can no longer guarantee what the White House’s strategy will be, and many predict it will be unclear until the end of the month.

And, even after Mulvaney visited with House Republicans and told them he was advising against a shutdown, some GOP leaders were noncommittal about what would occur.

“What if?” House Majority Leader Kevin McCarthy (R-Calif.) said. “What if it rains?”