US President Donald Trump a signed a spending bill which will reopen the federal government and pass a $400 billion budget deal.

The deal overcomes opposition from both liberal Democrats and tea party conservatives to endorse enormous spending increases despite looming trillion-dollar deficits.

Mr Trump tweeted, “Just signed Bill. Our Military will now be stronger than ever before. We love and need our Military and gave them everything — and more.

First time this has happened in a long time. Also means JOBS, JOBS, JOBS!”

The 240-186 vote came in the pre-dawn hours, putting to bed a five-and-a-half hour federal freeze that relatively few would notice.

Many who did quickly labelled it a pointless, head-scratching episode.

The shutdown was the second in three weeks.

The breakdown came largely in the Senate, when after a day of inaction, Republican Sen. Rand Paul of Kentucky went rogue and stalled a vote in protest over his party’s willingness to bust the budget.

But Democrats also had their divisions and wrangling, largely with liberal upset the measure were not tied to any plans to assist the “Dreamer” immigrants.

Most Democrats opposed the measure, following the lead of Minority Leader Nancy Pelosi, a California Democrat, who tried and failed to use the moment to secure a promise for a separate vote on immigration.

Up to the final minutes, it was not clear the bill would pass and many Democrats held their votes, allowing the tally to creep slowly and giving no indication which way it might fall.

Mr Trump also tweeted that America needed to elect more Republicans and that negotiations on “Dreamer immigrants” (known as DACA) would now start.

There was far less drama in the Senate, where the measure sailed through by a 71-28 tally.

The White House was forced to order the government shutdown shortly after midnight, but leaders quickly hustled to move before federal employees were due back at work, hoping to minimise the disruption.

A shutdown essentially cuts the federal workforce in half, with those dubbed non-essential not allowed to work, while military and essential workers remain on the job.

The House vote ensured most employees would report for work as usual.

The bill includes huge spending increases sought by Republicans for the Pentagon along with a big boost demanded by Democrats for domestic agencies. Both sides pressed for $89 billion for disaster relief, extending a host of health care provisions, and extending a slew of smaller tax breaks.

It also would increase the government’s debt cap, preventing a first-ever default on US obligations that was looming in just a few weeks.

Such debt limit votes are usually enormous headaches for Republican leaders, but the increase means another vote won’t occur before March 2019.

Just three weeks ago, Senate Democrats sparked a three-day partial government shutdown by filibustering a spending bill, seeking relief for “Dreamer” immigrants who’ve lived in the country illegally since they were children.