Congress struck a deal Wednesday night that will reopen the government through January 15 and allow the Treasury to borrow through early February or so. The deal did not defund Obamacare, as some Republicans had hoped it would.

House Speaker John Boehner of Ohio arrives on Capitol Hill, Wednesday. Bipartisan leaders in the Senate crafted a last-minute deal to fend off a looming U.S. default and to reopen the federal government. After the House's approval, the bill is on the way to the President's desk.

WASHINGTON — Congress passed legislation Wednesday night to avert a U.S. debt default and end a government shutdown, a bipartisan deal set along President Barack Obama's strict terms that left Republicans little to show for the epic political drama that threatened to rattle the world economy.

The Senate voted 81-18 to send the measure to the Republican-controlled House of Representatives, which passed it late in the evening 285-144. Obama pledged to sign it "immediately" after the House vote.

The bill reopens the government through Jan. 15 and permits the Treasury to borrow normally through Feb. 7 or perhaps a month longer. It includes nothing for Republicans demanding to eradicate or scale back Obama's signature health care overhaul.

"We fought the good fight. We just didn't win," conceded House Speaker John Boehner as lawmakers lined up to vote on the bill.

At the White House, Obama hailed the Senate's vote, saying that once the measure reaches his desk, "I will sign it immediately. We'll begin reopening our government immediately and we can begin to lift this cloud of uncertainty from our businesses and the American people."

Less than an hour later, as debate began in the House, Republican Rep. Harold Rogers said: "After two long weeks, it is time to end this government shutdown. It's time to take the threat of default off the table. It's time to restore some sanity to this place."

The stock market surged earlier Wednesday at the prospect of an end to the crisis that had threatened to shake confidence in the U.S. economy overseas.

More than two million federal workers — those who had remained on the job and those who had been furloughed — would be paid under the agreement.

Boehner and the rest of the top Republican leadership told their rank and file they would vote for the measure. But he vowed Republicans were not giving up on the fight to bring down U.S. debt and cripple "Obamacare," as the president's signature health care overhaul is known.

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

Harry Reid, the Democratic Senate majority leader, thanked Sen. Mitch McConnell, the Republican minority leader, for working with him to end what had become one of the nastiest partisan battles in recent Washington history.

"This is a time for reconciliation," Reid said.

A long line of polls charted a steep decline in public approval for Republicans in the course of what Republican Sen. John McCain pronounced a "shameful episode" in U.S. history.

The deal would end the bitter standoff for now, giving both parties time to cool off and come up with a broader budget plan or risk repeating the damaging cycle again in the new year.

The crisis began on Oct. 1 with a partial shutdown of the federal government after House Republicans refused to accept a temporary funding measure unless Obama agreed to defund or delay his health care law, known as "Obamacare." It escalated when House Republicans also refused to move on needed approval for raising the amount of money the Treasury can borrow to pay U.S. bills, raising the specter of a catastrophic default. Obama vowed repeatedly not to pay a "ransom" in order to get Congress to pass normally routine legislation.

The hard-right tea party faction of House Republicans, urged on by conservative Sen. Ted Cruz of Texas, had seen both deadlines as weapons that could be used to gut Obama's Affordable Care Act, designed to provide tens of millions of uninsured Americans with coverage. The Democrats remained united against any Republican threat to Obama's signature program, and Republicans in the House could not muster enough votes to pass their own plan to end the impasse.

McConnell said the time had come to back away for now from Republican efforts to undermine "Obamacare." But the feisty minority boss said Republicans had not given up on erasing it from the legislative books.

Passage in the House will depend heavily on minority Democrats to support it. The risky move was seen as imperiling the House leadership, but Boehner was apparently ready to do it and end the crisis that has badly damaged Republican approval among voters.

Looking forward, lawmakers were also concerned voters would punish them in next year's congressional elections. Polls show the public more inclined to blame Republicans.

Republican Sen. Lindsey Graham said the party had hurt its cause through the long and dangerous standoff.

"This package is just a joke compared to what we could have gotten if we had a more reasonable approach," he said.