* Senate passes bill, House follows suit
* Obama signs legislation just after midnight
* Federal workers told to expect return to work on Thursday
* Agreement extends borrowing authority until February
* Another budget showdown could loom next year
The U.S. Congress on Wednesday approved an 11th-hour deal to end a partial government shutdown and pull the world's biggest economy back from the brink of a historic debt default that could have threatened financial calamity.
Capping weeks of political brinkmanship that had unnerved global markets, President Barack Obama quickly signed the spending measure, which passed the Senate and House of Representatives after Republicans dropped efforts to use the legislation to force changes in his signature healthcare law.
The White House budget office told hundreds of thousands of federal workers, the bulk of whom had been idle for the past 16 days, to be ready to return to work on Thursday.
The down-to-the-wire deal, however, offers only a temporary fix and does not resolve the fundamental issues of spending and deficits that divide Republicans and Democrats. It funds the government until Jan. 15 and raises the debt ceiling until Feb. 7, so Americans face the possibility of another bitter budget fight and another government shutdown early next year.
With the deadlock broken just a day before the U.S. Treasury said it would exhaust its ability to borrow new funds, U.S. stocks surged on Wednesday, nearing an all-time high. Share markets in Asia also cheered the deal.
Taking the podium in the White House briefing room on Wednesday night, Obama said that with final congressional passage, "We can begin to lift this cloud of uncertainty and unease from our businesses and from the American people."
"Hopefully next time it won't be in the 11th hour. We've got to get out of the habit of governing by crisis," Obama said. He outmaneuvered Republicans by holding firm in defense of "Obamacare" to win agreement, with few strings attached, to end the 16-day shutdown.
World Bank President Jim Yong Kim said "the global economy dodged a potential catastrophe" with congressional approval of the deal to raise the $16.7 trillion U.S. debt ceiling.
The standoff between Republicans and the White House over funding the government forced the temporary lay-off of hundreds of thousands of federal workers from Oct. 1 and created concern that crisis-driven politics was the "new normal" in Washington.
While essential functions like defense and air traffic control continued during the crisis, national parks and agencies like the Environmental Protection Agency have been largely closed.
Senator John McCain, whose fellow Republicans triggered the crisis with demands that the Democratic president's "Obamacare" healthcare reform law be defunded, said earlier on Wednesday the deal marked the "end of an agonizing odyssey" for Americans.
"It is one of the most shameful chapters I have seen in the years I've spent in the Senate," said McCain, who had warned Republicans not to link their demands for Obamacare changes to the debt limit or government spending bill. Polls showed Republicans took a hit in public opinion over the standoff.
In the end, the Democratic-led Senate overwhelmingly passed the measure on a 81-18 vote, and the Republican-controlled House followed suit 285 to 144. Obama signed the 35-page bill just after midnight.
Although the deal would only extend U.S. borrowing authority until the first week of February, the Treasury Department would have tools to temporarily extend its borrowing capacity beyond that date if Congress failed to act early next year. But such techniques eventually run out.
In addition to lifting the federal debt limit, the deal calls for creating a House-Senate bipartisan commission to try to come up with long-term deficit-reduction ideas that would have to be approved by the full Congress. Their work would have to be completed by Dec. 13, but some lawmakers say the panel faces an extremely difficult task.
The agreement also includes some income verification procedures for those seeking subsidies under the 2010 healthcare law. But it was only a modest concession to Republicans, who surrendered on their latest attempt to delay or gut the healthcare package or include major changes, including the elimination of a medical device tax.
The congressional vote signaled a temporary ceasefire between Republicans and the White House in the latest struggle over spending and deficits that has at times paralyzed both decision-making and basic functions of government.
The political dysfunction has worried U.S. allies and creditors such as China, the biggest foreign holder of U.S. debt, and raised questions about the impact on America's prestige. The Treasury has said it risks hurting the country's reputation as a safe haven and stable financial center.
Senate Majority Leader Harry Reid and Republican leader Mitch McConnell announced the fiscal agreement on the Senate floor earlier on Wednesday, and its passage was eased when the main Republican critic of the deal, Senator Ted Cruz of Texas, said he would not use procedural moves to delay a vote.
The agreement stacked up as a political achievement for Obama, who refused to negotiate on changes to the healthcare law, and a defeat for Republicans, who were driven by Tea Party conservatives in their ranks and suffered a backlash in public opinion polls.
There was no immediate sign that House Speaker John Boehner's leadership position was at risk despite having conceded defeat in the budget battle.
Several Republican lawmakers suggested he may have strengthened his standing among the rank-and-file, who gave him a standing ovation at an afternoon meeting.
But Cruz, a Tea Party-backed senator with 2016 presidential aspirations, denounced the fiscal accord as a "terrible deal" and accused fellow Republicans of giving in too easily in their bid to derail Obamacare.
Obama's Democrats avoided claims of victory. "The bottom line is, millions suffered, millions didn't get pay checks, the economy was dragged down," said Senator Charles Schumer. "This is not a happy day, it is a somber day."
The fight over Obamacare rapidly grew into a brawl over the debt ceiling, threatening a default that global financial organizations warned could throw the United States back into recession and cause a global economic disaster.
Fitch Ratings had warned on Tuesday that it could cut the U.S. sovereign credit rating from AAA, citing the political brinkmanship over raising the debt ceiling.
A resolution to the crisis cannot come soon enough for many companies. American consumers have put away their wallets, at least temporarily, instead of spending on big-ticket items like cars and recreational vehicles.
"We're sort of 'crises-ed' out," said Tammy Darvish, vice president of DARCARS Automotive Group, a family-run company that owns 21 auto dealerships in the greater Washington area.