US president Donald Trump has signed a 400 billion dollar (£287 billion) budget deal that sharply boosts spending and swells the federal deficit, ending a brief federal government shutdown that took place while most Americans were sleeping.

Both the house of representatives and the senate approved a bill to keep the government funded until March 23, overcoming opposition from liberal Democrats as well as tea party conservatives to endorse enormous spending increases despite looming trillion-dollar deficits.

The house voted 240-186 to approve the bill just before dawn, hours after the senate had approved the measure on a 71-28 vote.

Mr Trump tweeted that he had signed the bill, writing that the US military “will now be stronger than ever before”. The budget bill “also means JOBS, JOBS, JOBS!”, the president tweeted.

The twin votes put to rest a brief federal freeze – the second in three weeks – which many commentators branded pointless.

The breakdown came largely in the senate, when, after a day of inaction, Republican senator Rand Paul of Kentucky went rogue and stalled a vote in protest over his party’s willingness to burst the budget. Democrats also experienced internal divisions, with liberals upset the measures were not tied to any plans to assist the “Dreamer” immigrants, who were brought to the country illegally as children.

House Minority Leader Nancy Pelosi 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 in the House, and many Democrats held their votes, allowing the tally to creep up slowly and giving no indication which way it might fall.

House speaker Paul Ryan urged Congress to avoid a “second needless shutdown in a matter of weeks — entirely needless”.

In the end, 73 Democrats voted in favour of the bill in the House, while 67 Republicans opposed it.

There was far less drama in the senate, where the measure sailed through by 71 votes to 28 once Mr Paul’s protest ran its course.

The budget agreement is married to a six-week temporary funding bill needed to keep the government operating and to provide time to implement the budget pact.

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 dollars (£64 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 looms in just a few weeks.