US senators scrambled together an eleventh hour compromise Wednesday that they hoped might protect Washington's battered financial standing by heading off fears of a default.
The Senate deal must still pass a divided and unpredictable House of Representatives, but lawmakers were hopeful it will allow the US government to reopen and keep borrowing to meet its obligations.
"I hope that we're nearing the end of this ordeal, this impasse which never should have happened in the first place," said Senator Susan Collins, a Republican who has led efforts to broker a compromise.
At midnight (0400 GMT), the US economy was to sail into uncharted waters where the Treasury would no longer be able to borrow more to meet its obligations and avert a devastating debt default.
The only way to avert this peril, which could send global markets into turmoil and threaten another recession, would be for Congress to agree to raise the US government's $16.7 trillion debt ceiling.
Senate leaders met to hammer out a compromise, after a previous effort in the Republican-led House collapsed in chaos on Tuesday.
"The America people are tired of where we are," Senator Kelly Ayotte, a Republican, said. "They're tired of the brinksmanship, and so they want us to get this resolved now for them -- today, hopefully."
Ayotte and other senators said that they understood that senate leaders had agreed the terms of a deal that could pass, and that it would be sent first to the House.
If it is approved there, it would return to the senate, where lawmakers hope to rapidly pass it into law.
Conservatives from the Tea Party movement in the House have thus far thwarted votes on the debt ceiling and on passing a budget, demanding concessions from President Barack Obama.
Obama's Democrats have refused to allow Republicans to hold the budget and debt ceiling votes to "ransom" with attempts to defund or delay the president's landmark Obamacare health insurance reform.
The stand-off has forced the US federal government into a partial shutdown, and if it continues past midnight it would put the United States in a position where it might not be able to pay its debts.
Markets have been watching the mess carefully, but have not panicked, most traders assuming that Washington will scrape together a deal before triggering global financial calamity.
US stocks surged as soon as reports began coming out from the Senate on the prospective deal.
Just before midday the Dow Jones industrial average was up by 185 points, or 1.2 percent, to 15,353.41, while the S&P 500 added 21 points, or 1.3 percent, to 1,719.41.
The Fitch ratings agency had underlined the seriousness of the situation by putting the US government's AAA credit rating on a downgrade warning, and European markets slid in morning trade.
The Senate has a Democratic majority and would back a straight vote to raise the debt ceiling.
The remaining hurdle is the House, where Republican Speaker John Boehner has proved unable to control his restive caucus.
With the Tea Party to his right insisting on standing firm, Boehner has thus far proved unwilling to use minority Democratic votes to pass even an interim budget or a temporary debt ceiling hike.
On Tuesday, in what was essentially a wasted day, House Republicans floated a plan to extend US borrowing authority until February 7 and re-open the government until December 15.
The draft bills would have constrained aspects of Obama's signature health care law and stood no chance of passing the Senate.
Boehner instead tried to use the measures to corral his Tea Party faction and pressure the Senate, but in the end was unable to amass enough Republican votes to even put the measures on the floor.
Republican Representative Scott Rigell said he expected Boehner would eventually break with the hardliners and call a vote.
"I am absolutely confident of this. The speaker will do whatever is required to preserve the credit rating of the United States of America, and I will support him in that effort," he told C-Span.
Major world powers have been left looking on in dismay, unable to do anything to protect their own economic interests, with many deeply invested in US Treasuries -- hitherto seen as a safe haven.
China and Japan, which between them hold $2.4 trillion in US Treasuries, have expressed alarmed and annoyance.