WASHINGTON — With less than two hours to spare, Congress voted late Wednesday night to end the 16-day government shutdown and avoid a federal default that experts warned could push the U.S. back into recession.

The Senate voted 81-18 on a bill brokered by Senate Majority Leader Harry Reid, D-Nev., and Minority Leader Mitch McConnell, R-Ky., to allow additional borrowing through Feb. 7 and provide funding for government agencies through Jan. 15. The House followed suit, 285-144.

In a major defeat for Republicans, President Obama’s landmark health care law, the Affordable Care Act, escaped the bitter political process virtually unscathed.

But the deal leaves, at least temporarily, the “sequestration” budget cuts that took effect in March, and orders the starkly divided House and Senate to negotiate a budget agreement by mid-December. It also offers back pay for all federal employees who were furloughed because of the shutdown that started Oct. 1.

In Maine, the deal means Acadia National Park will reopen and give Bar Harbor-area businesses a chance to reduce some of the losses that the shutdown caused at the tail end of the 2013 tourist season. And more than 2,700 state employees who faced furloughs beginning Thursday will stay on the job.

Thousands of federal workers in the state had been furloughed, although many defense and shipyard workers were subsequently called back to work.

A default might have delayed Social Security and veterans’ pension payments to hundreds of thousands of Mainers or affected Medicaid and Medicare. Maine has one of the nation’s highest proportions of residents who rely on those programs.

Obama vowed to sign the bill into law quickly, just hours before the deadline when Treasury officials warned the country would bump up against its borrowing limit, known as the debt ceiling.

“Once this agreement arrives on my desk, I will sign it immediately,” Obama said after the Senate vote. “We’ll begin reopening our government immediately, and we can begin to lift this cloud of uncertainty and unease from our businesses and from the American people.”

House Speaker John Boehner, R-Ohio, said earlier Wednesday that his caucus would not further delay the bill, after weeks of unsuccessful attempts to use the budget negotiations to defund or gut the Affordable Care Act.

“We fought the good fight. We just didn’t win,” Boehner said, according to The Associated Press.

The agreement passed with support from all four members of Maine’s congressional delegation: Republican Sen. Susan Collins, independent Sen. Angus King and Democratic Reps. Chellie Pingree and Mike Michaud.

PLEASED, BUT REPRIEVE TEMPORARY

Collins played a key role in jump-starting negotiations by offering one of the first comprehensive proposals, then leading a bipartisan group whose recommendations helped frame the leadership’s negotiations.

“I continue to believe that our plan was a great path forward but I am pleased that it paved the way to what I hope will be a solution to the impasse that we are facing,” Collins said in a floor speech.

King, who was a member of the Collins-led group, described the deal as “an agreement that is not going to be acceptable or exciting to anyone” but one that addresses the immediate crises and allows Congress “to move forward on the nation’s problems.”

“Everybody is feeling positive about where we are, but I think everybody also realizes that this is a temporary reprieve,” King said, alluding to the fact that Congress will have to address the same issues early next year.

King, who is a member of the Senate Budget Committee, was named as one of the senators on the budget negotiation team.

The congressional action means that two million federal employees who have been working without pay or at home on furlough will be paid, ending 2½ weeks of frustrating uncertainty.

It means food inspectors, veterans’ benefits staffers, researchers and home loan processors will be back on the job this week.

The deal also eased nerves in the business and financial sectors, as evidenced by a jump in the stock market Wednesday.

With roughly $30 billion on hand and fluctuating revenues, Treasury Secretary Jack Lew had warned that he would soon be unable to pay all of the nation’s debts and might have to decide whether to pay, for example, Social Security benefits or the nation’s loan obligations.

Experts predicted that the resulting default could cause stocks to plummet, trigger a downgrade in the U.S. credit rating and undermine economic recovery around the globe.

“Averting this crisis is historic,” Reid said immediately after the vote. “Let’s be honest, it is a pain inflicted on our nation for no reason and we cannot make the same mistake again.”

both parties made compromises

The agreement includes concessions from both parties.

Democrats wanted longer time frames to extend government spending and the debt ceiling, while Republicans pushed for narrower windows. The end result is that a Congress plagued by partisan gridlock and brinksmanship will be forced to debate both the budget and the debt ceiling within a matter of months.

But the largely Democrat-driven deal was viewed as a stinging loss for Republicans, who were bearing more of the public blame for the shutdown.

Republicans sought to highlight their few successes in the negotiations — such as preserving spending limits within the “sequestration” budget cuts — but also looked ahead to the next fights.

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

The Reid-McConnell agreement differs from the legislative package put forward by the bipartisan group of 14 senators led by Collins.

For instance, the eventual Senate deal contains different end dates for funding the government and extending the debt ceiling. A proposal to delay a medical device tax within the Affordable Care Act was also dropped, as was language giving federal agencies flexibility to implement the “sequestration” budget cuts.

But the proposal includes a requirement included in the Collins-led plan that the government verify the incomes of people who seek federal subsidies for health insurance through Obamacare.

Their efforts — and Collins’ role, in particular — were lauded on the Senate floor Wednesday.

“Thank you for taking the time, having the courage and putting forward the ideas that you did,” Sen. Dianne Feinstein, D-Calif., told Collins.

some still targeting obamacare

The partial shutdown of federal government began on Oct. 1, after Sen. Ted Cruz, R-Texas, and House tea party members insisted that Congress vote to defund the Affordable Care Act as part of any agreement to keep agencies open.

In the weeks since, House Republicans have scaled back their demands while attempting to reopen individual federal programs. Buoyed by polls showing Republicans taking a political beating, Obama and the Democrats held firm in their insistence that Republicans fund all of government and not “hold hostage” the full faith and credit of the country over Obamacare.

The decision by Cruz and House Republicans earned sharp rebukes by numerous Senate Republicans, several of whom joined Collins’ effort to negotiate a bipartisan compromise as the shutdown dragged on.

Among them was Sen. Kelly Ayotte of New Hampshire, a young and rising Republican with strong support in conservative and tea party circles. On Wednesday, Ayotte was incredulous when a reporter mentioned that some conservatives hope to use next year’s budget and debt ceiling battles to defund the Affordable Care Act.

“If they are saying that the defunding issue is going to come up in three months again, then they have learned nothing from this,” she said.

Ayotte stressed that she opposes Obamacare and will work to change or repeal it, but said: “If we learned nothing else from this whole exercise, I hope we learned that we shouldn’t get behind a strategy that cannot succeed.”

Other Republicans promised that the fight is not over. McConnell, for instance, said Republicans “remain determined to repeal this terrible law.”

Underscoring the political pressures on Republicans, two influential groups with starkly different readings of the Senate compromise announced they would include Wednesday’s votes on their widely read “scorecards” of lawmakers.

Kevin Miller can be contacted at 317-6256 or at:kmiller@pressherald.comTwitter: KevinMillerDC