The US Congress has passed a bill to reopen the government and raise the federal debt limit, with hours to spare before the nation risked default.
The Democratic-controlled Senate’s bipartisan compromise won approval by 81 votes to 18.
The deal was then passed by 285-144 in the House of Representatives, whose Republican leadership begrudgingly agreed to support the measure.
It came hours before the deadline to raise the $16.7tn (¬£10.5tn) limit.
The bill yanked the US back from the brink of a budgetary abyss by extending the treasury’s borrowing authority until 7 February.
It also funds the government to 15 January, reopening closed federal agencies and bringing hundreds of thousands of furloughed employees back to work.
President Barack Obama signed the bill into law early on Thursday morning.
The White House budget office said federal workers should return to work on Thursday.
The deal, however, offers only a temporary solution and does not resolve the budgetary issues that fiercely divide Republicans and Democrats.
President Obama warned that US lawmakers must “earn back the trust of the American people”.
“We’ve got to get out of the habit of governing by crisis,” the Democratic president added, speaking after the Senate vote on Wednesday evening.
“My hope and expectation is everybody has learned there’s no reason why we can’t work on the issues at hand, why we can’t disagree between the parties without still being agreeable and make sure that we’re not inflicting harm on the American people when we do have disagreements.”
Also speaking after the first vote, Senate Democratic Majority leader Harry Reid said: “Let’s be honest, this is pain inflicted on a nation for no good reason and we cannot, cannot make the same mistake again.”
The US Treasury has been using what it called “extraordinary measures” to pay its bills since the nation reached its current debt limit in May.
It said those methods would be exhausted by 17 October, leaving the US unable to meet all of its debt and other fiscal obligations.
Politicians, bankers and economists had warned of dire global economic consequences unless an agreement to raise the US government’s borrowing limit was reached.
Meanwhile, ratings firm Standard & Poor’s said on Wednesday that the partial US government shutdown, the first in 17 years, had already shaved $24bn from the American economy and would cut growth significantly in the fourth quarter.
Spurred on by hardline conservatives, congressional Republicans forced the standoff on 1 October by demanding that President Obama defund or delay his signature healthcare overhaul.
But they have emerged with little to show for it – under the bill just passed, the law commonly known as Obamacare escapes relatively unscathed.
Congressional Republicans, who have borne the brunt of blame in opinion polls for the budget row, conceded defeat on Wednesday.
“We fought the good fight,” Republican House Speaker John Boehner said as lawmakers lined up to vote on the bill. “We just didn’t win.”
Amid warnings that the debacle could damage the party’s prospects in next year’s midterm elections, the political autopsy has already begun.
“This has been a really bad two weeks for the Republican Party,” Republican Senator Lindsey Graham said.
Senator John McCain, who was the party’s 2008 presidential nominee, told the upper chamber it had been “one of the more shameful chapters I have seen in the years I have spent here in the Senate”