WASHINGTON — Congress and the White House spent September bracing for a disruptive government shutdown, and most of October fearing a possible default on the federal debt.
In between, rebellious House Republicans ousted their speaker, John A. Boehner and derailed his preferred successor, Kevin McCarthy, forcing the rest of their party to plead with a reluctant Paul D. Ryan of Wisconsin to accepting the gavel and try to control a majority that his predecessor could not.
And then, suddenly — almost implausibly — a budget deal was delivered just before midnight on Monday that promises relative tranquillity if not a full-on détente. The rancor that had defined Congress gave way to a complex, 144-page bill. Its passage on Wednesday was virtually guaranteed before many lawmakers had a chance to read the table of contents.
Even when the House was in disarray, with Boehner's long career being brought low by the far-right Freedom Caucus, congressional leadership aides were negotiating with White House officials on the spending plan. But Boehner's resignation freed him to work with his longtime nemesis, Rep. Nancy Pelosi, the House Democratic leader, to clinch a deal and secure the needed votes.
The outcome was in some ways so unlikely, that the Senate Democratic leader, Sen. Harry Reid of Nevada, expressed concerned that Americans might conclude something was amiss.
"What has happened is nothing that should be alarming; it shouldn't be a surprise," Reid said. "But it should be of interest to the American people: We did what we should be doing, sitting down and talking through our differences."
As a result of the accord, officials said, congressional Republicans and the White House can return to the more conventional policy battles with stakes decidedly lower than a default or shutdown that could upend the global economy.
Under the proposed deal, short-term expenditures, notably on military programs, will rise and long-term budget caps will remain in place. Meanwhile, spending priorities will be set the old-fashioned way, by seasoned lawmakers on Appropriations subcommittees.
For sure, there will still be fights, and many may be magnified by the 2016 presidential race. And the next president will likely confront a need to raise the federal debt ceiling within weeks of taking office.
These and other consequences of their late-night, landmark deal began coming into focus on Tuesday.
The deal, which will increase spending by $80 billion over two years, is almost underwhelming in its modest size and scope. But after five years of all-out brawling, legislative gridlock and general dysfunction, that may be the inherent genius of it.
By combining the relatively small spending increases, which temporarily break through the budget limitations loathed by Democrats, with small cuts to entitlement programs loathed by Republicans, the accord reached Monday night seems to provide a compromise that will attract a solid majority of lawmakers in the House and Senate.
"You're going to see bricks flying from those that don't like the fact that there's a bipartisan agreement," said Boehner, who perhaps had more reason than anyone to celebrate a final achievement before leaving Congress at the end of the week. "But there it is. It's a solid agreement. And I told my colleagues there isn't any reason why any member should vote against this."
Conservative Republicans in the House, however, said they hated the deal and how it was pulled together, in negotiations behind closed doors.
Even as Ryan, who is expected to be elected the next speaker on Thursday, railed against the measure on television — telling CNN, "the process stinks" — he will start his job with a far less perilous agenda.
But for the most part, Democrats and Republicans began lining up in support of the agreement.
"Most importantly, we have affirmed that the full faith and credit of the United States is nonnegotiable and inviolable," Pelosi said.
With most of the 188 Democrats in the House expected to back the deal, it seemed that fewer than 50 of the chamber's 247 Republicans would be needed to assure its passage, which is expected in a floor vote on Wednesday.
The Senate majority leader, Sen. Mitch McConnell, R-Ky., said he would quickly take up the bill, and other Republicans predicted it would win swift approval.
"I think there will be bipartisan support," Sen. John Thune of South Dakota, the No. 3 Republican, said on Tuesday.
The White House, more relieved than rejoicing, also voiced support.
"It's an actual bipartisan compromise, which hasn't been happening a lot in Washington recently," President Barack Obama said during a speech to law enforcement officials in Chicago. "It allows us to plan for the future."
White House officials regarded the deal as a better one than they had dared to imagine even a few months ago, when the budget impasse with Republicans appeared to be careening toward another crisis.
Boehner's retirement announcement, on Sept. 25, changed all that, and he seemed emboldened by the prospect that he could "clean out the barn" for his successor.
White House aides quickly conveyed that they would be happy to take up their mops and brooms.
In the weeks since, Obama quietly dispatched Katie Beirne Fallon, his legislative affairs chief, and Brian Deese, his senior adviser and a longtime economic aide, to work out the details with aides to House and Senate leaders from both parties. Obama refrained from intervening personally except for the occasional phone call.
While passage of the new budget deal seemingly assured, there were also some wrinkles on Tuesday. An analysis by the Congressional Budget Office showed the bill coming up about $5 billion short of the savings needed to fully offset the roughly $80 billion in new spending.
Rep. Pete Sessions, R-Texas, chairman of the House Rules Committee, said that initial procedural votes would be delayed until congressional leaders and the White House resolved the $5 billion discrepancy. Negotiators had clearly intended that the bill not add to the deficit.
Sessions also suggested there were problems with a provision that would amend federal crop insurance programs, but it was unclear if there would be any changes.
There is also a $32 billion increase for emergency overseas operations by the Pentagon and State departments, bringing the total increase to $112 billion — a number that Democrats said exceeded their goals.
The cuts to Medicare would come mostly from continuing a previous reduction in payments to doctors and other health care providers that was due to expire; additional money would be saved by tightening eligibility requirements for Social Security disability insurance, which now vary from state to state.
As has been the case virtually from the moment he became speaker, Boehner was hammered on Tuesday by Republicans on his right flank.
Rep. Mick Mulvaney, R-S.C. and a founder of the Freedom Caucus, said: "We sort of knew John was selling us down the river on the debt ceiling. I don't think we realized he would actually sink the ship by adding on all of these additional spending measures and all of these other extraneous matters."
Rohit Kumar, a former adviser to McConnell who participated in past budget negotiations, said the deal offered a chance to return to more routine, if still adversarial debate, in Congress.
"Very rarely will you have somebody doing cartwheels through the chamber when you have got a compromise measure," Kumar. "This is the difference between campaigning and governing. In campaigns, you can promise people the stars; when you govern, you have to make tough choices."