The United States was close to averting the first default in its history last night (Wednesday night) after the Senate announced an 11th-hour compromise deal to re-open the government and raise the debt ceiling until early next year.
The short-term fix arrived only hours before today's deadline to raise the country's borrowing limit - apparently just in time to end a damaging budget stand-off that threatened to have disastrous consequences for the global economy.
The bipartisan agreement, which was due to be voted on by both houses of Congress last night, would re-open the government until Jan 15 and raise the US debt ceiling until Feb 17.
The Dow Jones surged 200 points after it emerged that a deal had finally been reached, fully 16 days after a federal government shutdown that saw several hundred thousand US government workers put on temporary unpaid leave.
The agreement put Congress in a race against time last night to pass the deal through the Republican-controlled House of Representatives in order to allow President Barack Obama to sign it into law before midnight tonight.
If passed, it represents a clear political victory for Mr Obama, who had refused to give into demands from Tea Party Republicans to roll back parts of his signature health care reforms, known as Obamacare, in exchange for re-opening the government.
However, the White House was careful not to gloat over its victory, particular before the deal had passed through Congress.
"There are no winners here. We said that from the beginning, and we're going to say it right up to the end because it's true.
The American people have paid a price for this," said Jay Carney, the White House spokesman.
"The economy has suffered because of it, and it was wholly unnecessary."
Harry Reid, the Democrat majority leader in the Senate, tried to be magnanimous as he announced the hard-won deal, striking a bipartisan tone as he called for a period of reconciliation between the warring parties.
"After weeks spent facing off across a partisan divide that often seemed too wide to cross, our country came to the brink of a disaster," he said, "But in the end, political adversaries set aside their differences and disagreements to prevent that disaster."
Mitch McConnell, the top Republican in the Senate who has been forced to contend with "no compromise" Tea Party members of his own ranks, led by the freshman Texas senator Ted Cruz, was much more downbeat.
"This is far less than many of us had hoped for, frankly, but it is far better than what some had sought," he said.
"Now it's time for Republicans to unite behind other crucial goals."
As part of the deal, Republicans and Democrats are to meet in a bipartisan conference to try to draw up a long-term plan to fix America's finances, with America's national debt predicted to exceed $17 trillion (pounds 10.7 trillion) by early next year.
Fears that Mr Cruz, who is bitterly opposed to the Obamacare reforms, would try to delay the passage of the Senate compromise by launching another of the 24-hour filibusters that bought him to national prominence last month, proved unfounded.
However he berated the "Washington establishment" for cutting a deal to end the shutdown and commended his Republican colleagues in the House of Representatives who had refused to allow their leader, speaker John Boehner, to compromise for so long.
"This is unfortunate, but nobody should be surprised that the Washington establishment is pushing back," Mr Cruz said, promising the fight against the health care law would continue.
"Nobody should be surprised at the resistance to change."
Despite Mr Cruz's claims, it appeared last night that Mr Boehner - after weeks of acceding to demands of his Tea Party caucus - was preparing to put the Senate compromise to a vote in the 432-member House and use Democrat votes to pass a deal that many of his members still virulently oppose.
After several hours of closed-door talks, Mr Boehner confirmed the climbdown, announcing that he would allow the House a free vote on the Senate compromise, saying that having "fought the good fight" there was no need for his members to stand against the deal.
He added: "That fight will continue. But blocking the bipartisan agreement reached today by the members of the Senate will not be a tactic for us" According to some estimates, fewer than 40 House Republicans were expected to vote for the Senate compromise - just enough to reach the 218 votes needed to pass the measure when combined with 200 Democrat votes.
Investors gave qualified support for the deal. Warren Buffett, the billionaire boss of Berkshire Hathaway, led calls for Democrats and Republicans to agree not to endlessly repeat the kind of damaging stand-offs seen in recent days.
"What needs to happen is both sides should say, 'we will not use the debt ceiling as a weapon any more. In fact, we should get rid of it entirely'," he told CNN.