The nation stepped back from the brink of default Wednesday as Congress approved a bill to reopen the federal government and raise the debt ceiling.

President Barack Obama said he’d sign the bill as soon as it reached him. The White House ordered federal employees to expect to return to work Thursday morning.

The Senate approved the proposal crafted by Senate Majority Leader Harry Reid, D-Nev., and Senate Minority Leader Mitch McConnell, R-Ky., on an 81-18 vote Wednesday night. Twenty-seven Republicans joined Democrats in backing the bill. About two hours later, the measure moved to the House of Representatives, where it was approved 285-144. Eighty-seven Republicans joined 198 Democrats in voting yes. All 144 no votes were Republicans.

“We fought the good fight. We just didn’t win,” House Speaker John Boehner, R-Ohio, said hours before the vote.

The partisan bickering and acrimony that enveloped the House during the 16-day shutdown was largely replaced by softer tones and talk of bipartisanship prior to Wednesday’s vote, perhaps to soothe and reassure the markets.

Rep. Spencer Bachus, R-Ala., former chair of the House Financial Services Committee, asked colleagues, “For one night let us talk about what is good for this country and not about the other party” before he voted for the measure.

“I’m pleased that cooler heads have finally prevailed,” said Rep. Charlie Dent, R-Pa. “This legislation must be supported but it should not be celebrated. No high-fives or spiking the football. . . . It’s not a win for anyone, particularly the institution of Congress or the president, for that matter.”

President Barack Obama, who spoke after the Senate vote, thanked Democrats and Republicans for their work and said he’d sign the measure “immediately,” to reopen the government and “begin to lift this cloud of uncertainty and unease from our businesses and from the American people.”

Obama’s remarks came before the House vote. He said he’d have more to say Thursday, declaring, “There’s a lot of work ahead of us, including our need to earn back the trust of the American people that’s been lost over the last few weeks.”

Obama suggested his focus will return to a stalled immigration overhaul, passing a farm bill and the federal budget.

“We could get all these things done even this year, if everybody comes together in a spirit of, how are we going to move this country forward and put the last three weeks behind us?” he said.

Obama thanked congressional leaders for reaching a resolution, but he added, “Hopefully next time it won’t be in the 11th hour. One of the things that I said throughout this process is, we’ve got to get out of the habit of governing by crisis.” He took no questions but turned and said “No” when a reporter asked whether the deal meant he and Congress would be back in the same place in three months.

The expected approval by Congress would reopen the shuttered parts of the government after 16 days and end for now the stalemate that started when House Republicans refused to approve funding for the government past Oct. 1 unless the Senate and Obama agreed to defund the new Affordable Care Act, dubbed Obamacare. It also would temporarily extend the government debt ceiling. The government was expected to run out of borrowing authority Thursday evening, raising the specter of default.

“The eyes of the world have been in Washington all week,” Reid said on the Senate floor. “And while they witnessed a great deal of political discord, today they’ll see Congress reaching historic bipartisan agreement to reopen government and avoid default on the nation’s bills.”

The compromise appeared to be a victory for Democrats, as the health care law was left relatively unscathed.

Under the deal, the government would be funded through Jan. 15 and the $16.7 trillion debt ceiling would be increased until Feb. 7. A bipartisan House-Senate conference committee – co-chaired by Senate Budget Committee Chairwoman Patty Murray, D-Wash., and House Budget Committee Chairman Paul Ryan, R-Wis. – would work on larger budget issues. The committee will have until Dec. 13 to complete its work and report to Congress.

McConnell said Republicans managed to preserve tenants of the 2011 Budget Control Act, which includes the mandatory domestic and defense cuts known as sequestration.

“That’s been a top priority for me and for my colleagues on the Republican side of the aisle throughout this debate,” he said. “And it’s been worth the effort.”

Still, McConnell acknowledged that Republicans came up short.

“This is far less than many of us had hoped for, frankly,” McConnell said. “But it’s far better than what some had sought. Now it’s time for Republicans to unite behind other crucial goals.”

Boehner also talked about preserving the Budget Control Act in announcing that he would not stand in the way of a House vote on the Senate plan.

“Blocking the bipartisan agreement reached today by members of the Senate will not be a tactic for us,” Boehner said. “In addition to the risk of default, doing so would open the door for the Democratic majority in Washington to raise taxes again on the American people and undo the spending caps in the 2011 Budget Control Act without replacing them with better spending cuts.”

Sen. Ted Cruz, R-Texas, who was at the forefront of the plan to tie government funding to a demand to defund Obamacare, signaled that he would not block a vote on the Reid-McConnell compromise.

“I have no objections of the timing of this vote, and the reason is simple,” Cruz said when asked whether he would filibuster the plan. “There’s nothing to be gained from delaying this vote one day or two days, the outcome will be the same.”

That said, Cruz blasted the deal, calling it a victory for the Washington establishment.

“The deal that has been cut provides no relief to the millions of Americans who are hurting because of Obamacare,” he said. “This is unfortunate, but nobody should be surprised that the Washington establishment is pushing back. Nobody should be surprised at the resistance to change.”

While passage of the compromise appeared certain in the Senate, its prospects in the House were less clear Wednesday afternoon.

It should pass with a combination of Democratic and moderate Republican votes. But tea party and outside conservative groups warned Republican lawmakers that they would pay a price if they voted for the deal.

The conservative Club for Growth sent emails to House and Senate Republicans urging them to vote no on the measure and warned that the vote will be included in the club’s 2013 legislative scorecard.

“This announced plan, the details of which aren’t completely known, appears to have little to no reforms in it,” wrote Andy Roth, the club’s vice president of government affairs. “There are no significant changes to Obamacare, nothing on the other major entitlements that are racked with trillions in unfunded liabilities, and no meaningful spending cuts either. If this bill passes, Congress will kick the can down the road, yet again.”

Tea party groups also were angered by the deal.

Jenny Beth Martin, co-founder of a group called Tea Party Patriots, called the Reid/McConnell deal “a complete sellout.”

“The House ‘leadership’ must stop playing ‘flinch’ with themselves and instead play hardball with the White House, the Senate, and the House,” Martin said in a statement. “Otherwise, hard-working Americans are going to bear the burden of this unaffordable law. The American people WILL hold those responsible for this mess accountable.”

Senate Republicans, however, appeared ready to move on from the shutdown and debt ceiling crisis.

“We’ve been asking from the beginning what’s the ending, how does this end, how do you achieve what you’re purporting to achieve on defunding Obamacare, and I never got an answer to that,” said Sen. Kelly Ayotte, R-N.H. “If we learned nothing else from this whole exercise, I hope we learned that we shouldn’t get behind a strategy that cannot succeed. And by the way, let’s not forget that the government has been shut down but the Obamacare exchanges are still open.”

But for some lawmakers who were elected specifically to kill the health care law, the battle continues.