Congress gave final approval Friday to a giant $1.3 trillion spending bill that ends the budget battles for now, but only after late obstacles skirted close to another shutdown as conservatives objected to big outlays on Democratic priorities at a time when Republicans control the House, Senate and White House.
Senate passage shortly after midnight averted a third federal shutdown this year, an outcome both parties wanted to avoid. But in crafting a sweeping deal that busts budget caps, they've stirred conservative opposition and set the contours for the next funding fight ahead of the midterm elections.
The House easily approved the measure Thursday, 256-167, a bipartisan tally that underscored the popularity of the compromise, which funds the government through September. It beefs up military and domestic programs, delivering federal funds to every corner of the country.
But action stalled in the Senate, as conservatives ran the clock in protest. Then, an unusual glitch arose when Sen. James Risch, R-Idaho, wanted to remove a provision to rename a forest in his home state after the late Cecil Andrus, a four-term Democratic governor.
At one point, Sen. Bob Corker, R-Tenn., stepped forward to declare the entire late-night scene "ridiculous. It's juvenile."
Once the opponents relented, the Senate began voting, clearing the package by a 65-32 vote a full day before Friday's midnight deadline to fund the government.
"Shame, shame. A pox on both Houses - and parties," tweeted Sen. Rand Paul, R-Ky., who spent the afternoon tweeting details found in the 2,200-page bill that was released the night before. "No one has read it. Congress is broken."
Paul said later he knew he could only delay, but not stop, the outcome and had made his point.
The omnibus spending bill was supposed to be an antidote to the stopgap measures Congress has been forced to pass — five in this fiscal year alone — to keep government temporarily running amid partisan fiscal disputes.
Leaders delivered on President Donald Trump's top priorities of boosting Pentagon coffers and starting work his promised border wall, while compromising with Democrats on funds for road building, child care development, fighting the opioid crisis and more.
But the result has been unimaginable to many Republicans after campaigning on spending restraints and balanced budgets. Along with the recent GOP tax cuts law, the bill that stood a foot tall at some lawmakers' desks ushers in the return of $1 trillion deficits.
Trump only reluctantly backed the bill he would have to sign, according to Republican lawmakers and aides, who acknowledged the deal involved necessary trade-offs for the Democratic votes that were needed for passage despite their majority lock on Congress.
"Obviously he doesn't like this process — it's dangerous to put it up to the 11th hour like this," said Sen. David Perdue, R-Ga., who opposes the bill and speaks regularly to Trump. "The president, and our leadership, and the leadership in the House got together and said, Look, we don't like what the Democrats are doing, we got to fund the government."
White House legislative director Marc Short framed it as a compromise. "I can't sit here and tell you and your viewers that we love everything in the bill," he said on Fox. "But we think that we got many of our priorities funded."
Trying to smooth over differences, Republican leaders focused on military increases that were once core to the party's brand as guardians of national security.
"Vote yes for our military. Vote yes for the safety and the security of this country," said House Speaker Paul Ryan, R-Wis., ahead of voting.
But even that remained a hard sell. In all, 90 House Republicans, including many from the conservative House Freedom Caucus, voted against the bill, as did two dozen Republicans in the Senate.
It was a sign of the entrenched GOP divisions that have made leadership's job controlling the majority difficult. They will likely repeat on the next budget battle in fall.
Democrats faced their own divisions, particularly after failing to resolve the stalemate over shielding young Dreamer immigrants from deportation as Trump's decision to end the Deferred Action for Childhood Arrivals program has left it for the courts to decide.
Instead, Trump won $1.6 billion to begin building and replacing segments of the wall along the border with Mexico. The Congressional Hispanic Caucus opposed the bill.
Also missing from the package was a renewal of federal insurance subsidies to curb premium costs on the Affordable Care Act exchanges. Trump ended some of those payments as part of his effort to scuttle President Barack Obama's health care law, but Republicans have joined Democrats in trying to revive them.
Bipartisan efforts to restore the subsidies, and provide additional help for insurance carriers, foundered over disagreements on how tight abortion restrictions should be on using the money for private insurance plans. Senate Republicans made a last-ditch effort to tuck the insurance provisions into the bill, but Democrats refused to yield on abortion restrictions.
Still, Democrats were beyond pleased with the outcome. Minority Leader Nancy Pelosi, D-Calif., chronicled the party's many gains, and noted they could have just have easily withheld votes Republicans needed to avert another shutdown.
"We chose to use our leverage to help this bill pass," Pelosi said.
Senate Minority Leader Chuck Schumer, D-N.Y., said as the minority party in Congress, "We feel good." He added, "We produced a darn good bill."
Associated Press writers Matthew Daly and Jill Colvin contributed to this report.
Follow Mascaro on Twitter at https://twitter.com/LisaMascaro and Fram at https://twitter.com/AsFram