President Trump is threatening chaos to win concessions from Congress on his immigration demands, disrupting Republican leaders’ carefully scripted plan to avoid a politically disastrous government shutdown just weeks before the midterm elections. 

Senate Majority Leader Mitch McConnell (R-Ky.) and House Speaker Paul D. Ryan (R-Wis.) have laid out a strategy to fund more than half of federal agencies by Sept. 30, punting some of the more contentious fights — such as money for Trump’s long-sought U.S.-Mexico border wall — until after the elections. But the president’s conflicting signals — encouraging in private, hard-line in public — call into question whether the GOP leaders’ plan will succeed.

“If we don’t get border security after many, many years of talk within the United States, I would have no problem doing a shutdown,” Trump said Monday, re­iterating a point he made on Twitter over the weekend. That comes nearly one week after Ryan and McConnell briefed Trump on their strategy to fund the government in piecemeal installments well before the September deadline.

McConnell and other Republicans, for their part, remain upbeat that Congress can avert halting government operations, which could be electorally devastating as the GOP tries to show how productive its majorities can be in delivering on conservative priorities. But Trump’s comments inject uncertainty into an appropriations process that had been, somewhat surprisingly, moving along in Congress with few glitches. 

“I’m confident we can avoid a shutdown,” McConnell told The Washington Post on Monday.

Yet Trump has shown repeatedly that he can be impulsive and erratic, even on issues where Republicans crave predictability and cover from the president to cast tough votes. 

After administration officials and lawmakers painstakingly negotiated a sweeping, $1.3 trillion spending measure in March, Trump publicly waffled over whether to sign the bill the day that the government was slated to run out of money amid conservative cries of fiscal irresponsibility. 

And last month, Trump pledged to House Republicans that he would be “1,000 percent behind you” in passing immigration bills. Yet two days later, he tweeted the GOP “should stop wasting their time on Immigration until after we elect more Senators and Congressmen/women in November.”

His continued focus on tying government funding to immigration — a signature issue for Trump, who rose to the top of the Republican presidential ranks with a hard-line stance that enthralled the base — also underscores how his desire to rally his core voters can run roughshod over congressional Republicans who are trying to show that an all-GOP government can run Washington. 

Trump’s weekend tweets, and his subsequent threats on Monday, upended an otherwise calm appropriations process this year on Capitol Hill — a sharp contrast to the frenzy in recent years that consumed lawmakers, who ended up producing a massive, catchall spending measure that few in Congress seemed to like.

After Trump promised never to sign a catchall spending bill in March, the House and Senate have passed several smaller government funding measures with relative ease. 

The House has backed six of the 12 appropriations bills: funding for the Interior Department and related environmental programs; financial services; energy and water programs; military construction and veterans affairs; the Pentagon; and the legislative branch. The Senate has passed three of those bills (energy and water; legislative branch; military construction) and plans to clear four more (Interior funding; financial services; transportation and housing; and agriculture programs) this week. 

“It’s been going well, very well,” said Sen. Susan Collins (R-Maine), who chairs the panel overseeing funding for transportation, housing and related programs. “That’s why I was surprised to see [Trump’s shutdown comments] because we’ve made more progress, more quickly this year than in many years.”

Senate Appropriations Committee Chairman Richard C. Shelby (R-Ala.), who has worked smoothly with the committee’s top Democrat, Sen. Patrick J. Leahy (Vt.), to block controversial policy provisions from the Senate’s spending bills, said he didn’t know why Trump was threatening a shutdown. 

“It might help him, it might not help him, but it doesn’t help us right now,” Shelby said.

Sen. John Thune (R-S.D.) said he assumed Trump’s words were a “negotiating tactic. I hope it’s a negotiating tactic.”

If all goes to Ryan and McConnell’s plan, Trump will have signed more than a half-dozen of the 12 government spending measures well ahead of the Sept. 30 deadline. But that strategy depends on Trump following through; Trump did note Monday that “we are already approving things in various bills,” including the military. 

“I would certainly be willing to consider a shutdown if we don’t get proper border security,” Trump said at a news conference alongside Italian Prime Minister Giuseppe Conte, whom Trump praised for taking similar hard-line positions on immigration. 

It was a much different tone inside the two congressional leaders’ meeting with Trump last week at the White House. Officials briefed on the meeting said the president was on board with the plan to fund the government through the piecemeal bills; one of the officials said the president had also agreed to delay a fight for border wall funding — which is contained within the spending bill for the Department of Homeland Security — until after the midterm elections.

Other spending fights that will probably be delayed until after the elections include funding for the Justice Department, as well as money for the State Department and foreign operations. 

Congressional Republican aides have also privately rationalized that Trump did not mention a September time frame as he agitated for an immigration-provoked shutdown — which lines up with the leaders’ strategy to fight over border wall funding after the midterms. 

The House has set aside about $5 billion of wall funding in its homeland security bill, an amount that has been endorsed by the White House. The Senate would allocate about $1.6 billion. The Senate and House still have to reconcile the spending bills that have passed their respective chambers.

And some Republican officials privately raised concerns Monday that no matter how carefully the spending package is negotiated, the impetuous Trump could always upend it with a 280-character burst on Twitter or impromptu comments at the White House. 

“Trump has not empowered his legislative folks to cut deals,” said one senior GOP aide. “There’s only one decision-maker in the White House, and that’s him.”

One White House official said Trump’s immigration-related demands have been raised by the administration “at every point” during the government spending talks. “Not new asks,” the official said.

“I know he’s frustrated — and I am, too — that we haven’t taken steps to adequately deal with border security, but we’ve got an orderly appropriations process going through here,” Senate Majority Whip John Cornyn (R-Tex.) said Monday. Of Trump’s unpredictability, Cornyn commented: “He has his own unique style.”

Paul Kane and Mike DeBonis contributed to this report.