US politicians have struck a last-minute deal to avert a catastrophic debt default that threatened to derail the global economy.
Stock markets rallied as Democrat and Republican leaders in the Senate reached an agreement to avoid missing a looming deadline on the US borrowing ceiling.
The deal was the culmination of weeks of political brinkmanship as opponents on both sides refused to blink.
The Republican-controlled House of Representatives and the Senate, which has a Democrat majority, must still approve the plan before it is signed off by President Barack Obama in time to meet the debt deadline.
However, speaker of the House of Representatives John Boehner has said his chamber will not block the Senate plan.
In a brief statement, Mr Boehner said his Republican lawmakers would continue the fight against President Obama's healthcare overhaul and for fiscal responsibility.
The deal came after shares began to turn sharply downwards with the deadline approaching amid a warning from billionaire investor Warren Buffett that the debt ceiling was a "political weapon of mass destruction", comparing the threat of default to a nuclear bomb.
The International Monetary Fund had warned at the weekend that a default risked plunging the world back into recession.
However the mood was transformed as reports of a deal began to take shape, with Wall Street's Dow Jones Industrial Average up more than 200 points at one stage and the FTSE 100 recovering losses to finish ahead at the close.
Democratic leader Harry Reid said Senate leaders had reached an agreement to avoid the default and end the 16-day-old shutdown.
Non-essential government services closed during that period would be reopened - but only until a new deadline of 15 January for the time being.
The US' borrowing authority was increased until 7 February.
Mr Reid said: "The compromise we reached will provide our economy with the stability it desperately needs."
The proposed deal does not contain demands by House Republicans to rollback President Barack Obama's healthcare overhaul.
US politicians have until tomorrow to raise America's debt ceiling - lifting the cap on how much it can borrow.
Otherwise they risk the administration being unable to honour IOUs on Treasury debt, a mainstay of the global economy.
A main Republican critic of the deal, Senator Ted Cruz of Texas, said he would not use procedural moves to delay a vote.
Mr Cruz and other Republicans backed by the conservative Tea Party movement want to repeal or delay the healthcare law.
The initial fight over so-called "Obamacare" turned into a bigger argument over the debt ceiling, threatening a default that would have reverberations around the world.
Both Democrats and Republicans are confident that the US House of Representatives will have enough votes to pass the bipartisan Senate plan.
The deal that emerged will basically give Mr Obama what he has demanded for months: A straight-forward debt limit hike and government funding bill.