Media playback is unsupported on your device Media caption Katy Watson reports on the deal struck over the US budget crisis

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 Democrat-controlled Senate passed the measure by 81 votes to 18, and the Republican-controlled House of Representatives by 285 votes to 144.

Despite reluctant support by the House Republican leader, most of the party's lawmakers there voted against it.

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 after 16 days of partial government shutdown and bringing hundreds of thousands of employees back to work.

President Barack Obama signed the bill into law early on Thursday morning.

Following the deal, shares in Tokyo closed higher, while in Europe they fell slightly in early trading.

'Governing by crisis'

The White House budget office said federal workers should return to work on Thursday.

The idea that this marks a fight back by moderates against the radical right is, I think, wishful thinking by liberals

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."

Media playback is unsupported on your device Media caption Los Angeles views on the political crisis: "I thought it was ridiculous"

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.

'Shameful'

But they have emerged with little to show for it - under the bill just passed, the law commonly known as Obamacare escapes relatively unscathed.

World press reaction New York Times editorial: "The Republican Party slunk away on Wednesday from its failed, ruinous strategy to get its way through the use of havoc"

editorial: "The Republican Party slunk away on Wednesday from its failed, ruinous strategy to get its way through the use of havoc" Commentary in China's The Nan Fang Daily : "If we want to get out of this passive unfavourable situation in the long term, we can only reduce the role of the US dollar and the US debt in the global market"

: "If we want to get out of this passive unfavourable situation in the long term, we can only reduce the role of the US dollar and the US debt in the global market" Philippe Gelie in France's Le Figaro: "The spectacle presented in Washington over the last few weeks goes beyond the excessive taste of the Americans for political drama" Reaction in full

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."

Mr Boehner said in a statement: "Our drive to stop the train wreck that is the president's health care law will continue."

In the House of Representatives, 144 Republicans voted against the bill. But 87 voted in favour, allowing it to pass.

Amid warnings that the debacle could damage the party's prospects in next year's midterm elections, the political autopsy has already begun.

Media playback is unsupported on your device Media caption Senator John McCain considers how the debt deal played out for Republicans

"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".

He told the BBC that it was "disturbing when Republicans attack Republicans", and that "we're going to continue a debate within our party as to the direction of the party and how we should handle things."

"I'm guardedly optimistic and confident that we won't revisit it this way again," he said. "The reaction of the American people is very, very negative, and understandably so."