The US Congress has endorsed bipartisan legislation to end a protracted budget crisis, pulling the country from the brink of a looming debt default and signaling the end of a two-week government shutdown.

The bill, a temporary fix that will last through until the start of 2014, passed the US Senate 81-18 with a majority of both Democrats and Republicans. It then passed the US House of Represenatives by 285 votes to 144, with a majority of Democrats bolstered by a minority of Republicans.

In brief remarks at the White House, shortly before the House was due to vote, president Barack Obama said he hoped the deal would "lift the cloud of uncertainty" that has hung over the country in recent weeks.

"Once this agreement arrives on my desk, I will sign it immediately," he said, saying he hoped the next round of spending negotiations between the parties would be more successful.

"Hopefully next time it won't be in the eleventh hour. We've got to get out of the habit of governing by crisis."

Earlier in the day, House Republican leaders conceded defeat in their two-week battle to derail Obama's healthcare reforms on Wednesday, and said they would not block the deal, despite winning virtually no concessions.

With just hours to go until the start of the deadline set by the US Treasury for extending the debt limit, House speaker John Boehner signalled he was ready to accept a Senate-drafted peace deal that contained almost no concessions to conservatives who had driven the country the precipice of a new financial crisis.

The Republican capitulation was swift and dramatic. "We fought the good fight, but we just didn't win," Boehner told a local TV station in his hometown of Cincinnati, Ohio.

Moderate Republicans, bitter at the wounds inflicted on the party by a fight that ended in an almost complete failure to achieve any of the concessions they had sought, lashed out at their conservative colleagues.

The standoff ended just after midday when Harry Reid, the majority leader, announced the deal on the the floor of the Senate. Calling for all sides to work together, he said: "Now is not the time for pointing the fingers of blame. Now is the time for reconciliation."

Mitch McConnell, the Republican minority leader, acknowledged the fight was over. "This has been a long, challenging few weeks," McConnell said. "This is far less than many of us had hoped for, but it is far better than some had sought."

The deal, crafted by Reid and McConnell, will fund the government until 15 January and lift the debt ceiling until 7 February. It will force both sides into a formal budget conference in an attempt to reach a longer-term deal by 13 December.

The only apparent change to the Affordable Care Act, which Republicans had targeted when they precipitated the government shutdown, involves asking the Obama administration to carry out better checks on the incomes of people registering for insurance exchanges.

A senior Republican aide told the Guardian that Boehner had agreed to allow the House to vote on the deal, which in practice means it would pass with support from Democrats and moderate Republicans. The vote was due to take place on Wednesday evening.

At 3pm, Boehner hosted a short meeting with Republicans in the House. Sources inside said he effectively told his colleagues they had lost the fight, before he was given a tepid applause.

Several congressman leaving the meeting conceded that hardline Republican tactics, which forced a two-week government shutdown and took the government to the brink of an economic crisis, had left them empty-handed.

The White House welcomed the Senate deal but cautioned that the battle would not be finally over until House lawmakers voted in favour of it. "The president applauds leader Reid and minority leader McConnell for working together to forge this compromise and encourages the Congress to act swiftly to end this shutdown and protect the full faith and credit of the United States of America," said Obama's chief spokesman, Jay Carney.

The White House also hinted that Obama may use the defeat of conservatives in Congress as a way to push ahead with other administration priorities such as immigration reform, that were previously blocked from coming to the floor of the House of Representatives.

"The president believes that one of the consequences of these manufactured crises is that time is taken away from the pursuit of other goals that we have as a nation," added Carney. "That includes ... the project of bringing about legislation that he can sign that comprehensively reforms our immigration system."

Recriminations among Republicans flew thick and fast, with moderates accusing House conservatives of trashing the party's reputation in pursuit of an impossible ambition to repeal or defund the Affordable Care Act, also known as Obamacare.

Senator Lindsey Graham, of South Carolina, said this had "been the best two weeks for the Democratic party in recent times".

"When we evaluate the last couple of weeks, it should be entitled the time of great lost opportunity. If we had been focused on the rollout of Obamacare and its confusion, public support would have diminished. Instead, our numbers have gone down, Obamacare has mysteriously gone up, and other than that, this has been great."

Graham was scathing about the influence of conservative advocacy groups such as Heritage Action, which torpedoed a deal on Tuesday when it threatened to withdraw support from Republicans who backed it. He also warned of the damage that the party had inflicted on itself: "The way we are behaving and the path we have taken the last couple of weeks leads to a marginalised party in the eyes of the American people," he said.

Ted Cruz, the first-term Republican senator from Texas who had led the rebellion against Obamacare with a marathon 21-hour speech last month, was unrepentant but said he would not stand in the way of the Senate vote even though he opposes the deal.

Underscoring the fault lines in the Republican party, he blamed fellow senators for failing to go along with his strategy. "Unfortunately the Senate chose not to follow the House and in particular we saw real division among Senate Republicans. Had Senate Republicans united and supported House Republicans the outcome of this would have been very, very different," Cruz said.

Shortly before the Senate vote, Cruz took to the floor to urge his colleagues to vote against it. "This is a terrible deal," he said. "It embodies everything about the Washington establishment that frustrates the American people."

It was the worst of all possible outcomes for Republicans. None of their stated goals were achieved, and polls showed that voters overwhelmingly blamed them for the crisis. By refusing to blink, Democrats pushed Republicans to show that they would not let the US default on its debts, making it hard for the GOP to repeat its tactic.

Charles Boustany, a Louisiana Republican Charles Boustany, said the Tea Party-backed members of the House of Representatives had put the GOP's position at risk. "This could trigger a wave of discontent that could wash out our Republican majority in the House if we're not careful – it's getting to that level," Boustany told the National Journal.

However, conservatives were equally robust in return. Thomas Massie, a Republican from Kentucky, admitted his side had emerged with "a goose egg". "We got nothing," he said.

Asked if his party had been damaged in any way over the last two weeks, he replied: "No, I don't think so. I think we'll find out in 2014, at the ballot box."