WASHINGTON – Following up one of the most chaotic days of his administration, President Donald Trump began Friday by demanding the Senate approve a new funding plan for a border wall or watch the government shut down at midnight.

"Properly designed and built Walls work," Trump wrote on Twitter, a day after his defense secretary resigned in protest, allies protested plans to withdraw from Syria and Afghanistan, and lawmakers braced for the prospect of a government shutdown.

Trump was at the center of it all, including his rejection of a spending plan that would keep the government open because in his view it lacked sufficient money for "border security," including his proposed wall on the U.S.-Mexico border.

While Democrats called the wall an ineffective waste of money – and not worth shutting down the government – Trump spent his tweet storm defending the idea by claiming that walls have worked for "thousands of years," just like the wheel.

"I know tech better than anyone," Trump said in one post.

He also warned that if Democrats don't drop their opposition to funding of the border wall, "there will be a shutdown that will last for a very long time."

After telling congressional Republicans midday Thursday he would oppose a temporary spending proposal, the House later approved a new spending bill with the $5 billion in wall funding Trump is seeking.

The revised bill's prospects in the Senate, however, are uncertain at best because Democrats have the numbers to block passage.

If a new spending bill is not approved, the existing one expires at midnight and parts of the government will shutdown.

As the budget battle raged, Defense Secretary Jim Mattis stunned lawmakers by announcing his resignation in a letter that rebuked much of Trump's "America First" foreign policy.

Mattis and other military leaders opposed Trump's decision this week to withdraw all 2,000 U.S. troops from Syria, as well as a developing plan to withdraw up to 7,000 U.S. troops from Afghanistan.

Bipartisan groups of lawmakers also opposed the Syria and Afghanistan withdrawal plans, saying the lack of U.S. force will give terrorist groups the space to grow and spread.

Trump confined his early Friday tweet storm to the wall and shutdown.

The president sought to put pressure on Senate Republican leader Mitch McConnell, saying he "should fight for the Wall and Border Security as hard as he fought for anything" and solicit Democrat votes.

If the measure fails, he said, "it will be a Democrat Shutdown!"

At one point, Trump urged McConnell to adopt the "nuclear option" – basically eliminating the filibuster rule and enabling the budget plan to pass with a simple majority. As it stands now, Republicans need 60 votes to overcome a Democratic filibuster.

While McConnell and others have supported the nuclear option for judicial nominations and other presidential appointments, they have opposed its use for policy matters. Some Republicans said they would oppose using the nuclear option in this case as well, effectively killing the idea.

Democrats noted that Trump himself just last week said he would be proud to shut down the government over the wall issue. Throughout the week, they said, the White House sent out signals it would support the short-term spending bill Congress spent days working on.

But Trump, after hearing from supporters and conservative commentators who urged him to hold out for full funding of the wall, told House Republican leaders he would oppose the version they had negotiated.

"President Trump is plunging the country into chaos," said Senate Democratic leader Chuck Schumer of New York, citing the Mattis resignation as well as a steep drop in the stock market.