Congress was racing Wednesday night to approve legislation ending the 16-day-old government shutdown and avert the potential for the first major debt default in U.S. history in a deal that gave President Obama most of what he sought — an open government and more borrowing authority without denting Obamacare.

The Senate voted 81-18 to approve the deal and sent it over to the House, which was expected to follow suit late in the night. House Speaker John A. Boehner had said that his troops wouldn’t stand in the way of the measure, which amounts to an almost complete surrender for the GOP.

“Blocking the bipartisan agreement reached today by the members of the Senate will not be a tactic for us,” he said, bringing to an end a bruising fight that has seen the GOP sink to historic lows in approval ratings, and exposed deep divisions within the party over tactics and policy.

Moments after the Senate vote, Mr. Obama took to the White House press briefing room and promised to sign the bill as soon as it gets to his desk.

“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,” he said. “With the shutdown behind us and budget committees forming, we now have the opportunity to focus on a sensible budget that is responsible, that is fair and that helps hard-working people all across this country.”

Still to be seen is whether the deal subdues the tea party, which had helped push Republicans to take a stand that in hindsight appears to have been futile.

Outside of Washington, the news of a deal was cheered. The mere announcement of a deal sent the financial markets soaring, with the Dow Jones Industrial Average leaping more than 200 points, for a one-day gain of 1.4 percent.

The agreement by Senate Majority Leader Harry Reid, Nevada Democrat, and his Republican counterpart, Sen. Mitch McConnell of Kentucky, would reopen the government with a stopgap spending bill running to Jan. 15, and would extend the government’s borrowing authority through at least Feb. 7. The two men also promised to name negotiators to a House-Senate conference committee to try to reach a final deal on a 2014 budget.

The only major concession Republicans won was to include strict income monitoring of those seeking taxpayer subsidies under Obamacare.

“We have sent a message to Americans from every state and citizens of every country that the United States lives up to its obligations,” Mr. Reid said. “Now Congress must return to its most important job — fostering economic growth and protecting middle-class families.”

Still to be seen is whether Mr. Reid and Mr. Obama achieved their greater goal, which was to try to undercut the political power of the tea party.

Sen. Charles E. Schumer, New York Democrat, said he hoped that would be the “silver lining that can come out of this gray cloud.”

“Out of this great darkness can come some light: the desire of both sides of the aisle, of the majority of both parties, to say, ‘Enough brinksmanship.’ Let us sit down, let us negotiate and let us move forward so this great country will be led by its government instead of pulled down by its government,” he said.

Mr. Obama’s signature will send the government lurching back into life — though much of it never shut down in the first place. The military, federal law enforcement and many other workers deemed “essential” never got furloughed, though they worked without pay.

Social Security checks continued to be mailed, and agencies that had their own funding, such as the Postal Service, also kept going.

The high-profile shutdowns did include national parks and refunds from the IRS.

The most Republicans could salvage from the fight was that they didn’t give up the budget sequesters. But neither did they lock them in.

Indeed, the stopgap spending bill, which ends Jan. 15, was timed to coincide with the next round of sequesters, giving Democrats another chance to undo them.

“Hopefully we’ve all learned some important lessons,” said Sen. John Cornyn of Texas, the second-ranking Republican in the chamber, as he ducked into his office off the Senate floor. He didn’t say who he was talking about, though moments later fellow Texas Sen. Ted Cruz went in to see Mr. Cornyn.

Mr. Cruz helped ignite the last three weeks of fighting by insisting Republicans refuse to fund the government until Mr. Obama canceled Obamacare. He spent August bolstering his case, aided by pressure groups which said they would punish lawmakers who didn’t support Mr. Cruz’s push by downgrading them on legislative scorecards.

“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,” said the Club for Growth, which said it was urging lawmakers to oppose the bill.

On the other side of the ledger was the U.S. Chamber of Commerce, which said it was scoring the vote as a “Yes.” Executive Vice President R. Bruce Josten said while there are major spending and tax issues to be fought over, a debt default shouldn’t ever be risked.

“The U.S. economy continues to grow only modestly, reinforcing the need for the federal government to resume its normal operations and to avoid the uncertainty and panic that would result from a historically unprecedented debt default,” he wrote to lawmakers.

For his part Mr. Cruz declined to delay the bill, which he could have done, just as he did in September. But he did have harsh words for his colleagues.

“This is a terrible deal. This deal embodies everything about the Washington establishment that frustrates the American people,” he said on the Senate floor, minutes before the vote. “This deal kicks the can down the road. It allows yet more debt, more deficit, more spending and it does absolutely nothing to provide relief for the millions of Americans who are hurting because of Obamacare.”

The Washington Times Comment Policy

The Washington Times is switching its third-party commenting system from Disqus to Spot.IM. You will need to either create an account with Spot.im or if you wish to use your Disqus account look under the Conversation for the link "Have a Disqus Account?". Please read our Comment Policy before commenting.