Updated December 11, 2014, 9:30 p.m.

The House narrowly passed the $1.013 trillion spending package late Thursday night on a vote of 219-206, as Republican leaders and the White House cobbled together just enough support to overcome opposition from liberals and the Democratic House minority leader, Nancy Pelosi. The bill now goes to the Senate, and House leaders moved quickly to approve a bill extending government funding for two days to avert a shutdown set to begin on Friday. Senate Majority Leader Harry Reid said the Senate would pass a two-day extension to avert a shutdown and debate the broader package on Friday.

Republican leaders had delayed the vote for several hours on Thursday when it seemed the bill lacked the necessary support. President Obama and White House officials furiously lobbied Democratic lawmakers to back it, arguing that this was a better deal than they'd be able to get next year when the GOP controls both chambers of Congress. Pelosi opposed it, however, on the grounds that Republicans had tarnished a bipartisan bill by inserting provisions benefitting Wall Street banks and wealthy political donors. In a lengthy meeting of the Democratic caucus Thursday evening, she told her members, according to a person in the room:"I'm giving you the leverage to do whatever you have to do. We have enough votes to show them never to do this again."

Updated December 11, 2014, 4:00 p.m.

Congress found itself on the brink of an unexpected government shutdown on Thursday as House Republican leaders were forced to postpone a vote on a $1.013 trillion spending package hours before their deadline.

The 1,600-page proposal, unveiled less than two days ago, would fund nearly the entire federal government through September, but Democrats revolted over an extraneous provision rolling back regulations on Wall Street. By mid-afternoon, Speaker John Boehner and his lieutenants were in a rare and awkward alliance with the White House in seeking to overcome opposition both from conservatives and liberals. President Obama and other administration officials scrambled to shore up support in their party and were phoning lawmakers late into the afternoon.

In perhaps the most surprising development, House Minority Leader Nancy Pelosi campaigned in harsh tones against the Obama administration, accusing a Democratic president she has loyally backed for six years of backing a measure that "blackmailed" her members. "This is a ransom. This is a blackmail," she declared in a fiery floor speech. She warned that the provision weakening regulations on derivatives trading, enacted in the 2010 Dodd-Frank Wall Street reform law, could lead to the same financial calamity that befell the nation when the economy collapsed in 2008. "We’re being asked to vote for a moral hazard," she said. "Why is this in an appropriations bill? Because it is the price of an appropriations bill."

But Democratic opponents are taking a big risk, as Boehner has warned them that if this bill fails, he'll bring up a stopgap measure that would push the fight into the new Congress that begins in January, when Republicans will have majorities in both the House and the Senate. Pelosi has used the fight over the spending bill to try to prove her relevance heading into the next Congress, when she will be leading a Democratic caucus smaller than at any time in decades. When GOP leaders delayed the vote, the former speaker sent off a missive to her members urging them to stand firm and insisting that Republicans "don't have enough votes to pass" the bill that Beltway insiders have derisively dubbed "the CRomnibus." "This increases our leverage to get two offensive provisions of the bill removed: the bank bailout and big money for campaigns provision," Pelosi wrote.

Introduced in the House on Tuesday, the measure funds all but one department in the federal government through next September. It boosts spending for the fight against Ebola and the war against the Islamic State while cutting funds for the IRS and the EPA. Earlier Thursday, Boehner voiced confidence the measure would clear the House. "I expect this bill will receive bipartisan support and pass," he told reporters. But the measure's prospects worsened during a procedural vote shortly before noon to bring the bill up for debate. With Democrats united in opposition, Boehner and his deputies had to persuade a handful of recalcitrant Republicans to support the motion in a vote that was briefly deadlocked and held open for twice its allotted time. The motion passed by a single vote, 214-212, to set up the final vote.

It was only after the House cleared that procedural hurdle that the Obama administration swooped in with a statement formally backing the measure, in an effort to persuade just enough Democrats to help Boehner muster enough votes to pass it. Josh Earnest, the White House press secretary, made clear that Obama opposed certain provisions in the bill, including those loosening rules for Wall Street and campaign contributions from wealthy donors. But he said:
“We can’t allow a disagreement over one thing to be a deal-breaker."

For Democrats, the decision offered a preview of the kind of choices they'll likely have to make routinely come January, when Republicans will control both Houses of Congress. Democratic negotiators argued that they accepted the distasteful policy provisions for Wall Street and campaign finance to avoid even worse measures that would strike core Democratic priorities like immigration and the Affordable Care Act.

Unlike the spending fight in October 2013, both parties were determined to avoid a shutdown at nearly any cost. Uncertain how the big spending bill would fare, Republicans were preparing multiple back-up plans to keep the government open on Friday. But still, the hours ticked away on Thursday afternoon with no action in the House. Even with the passage of the omnibus measure, the House is likely to approve a stopgap measure because procedural obstacles might prevent the Senate from passing it by midnight. Senator Elizabeth Warren was waging a campaign against the bill over the Wall Street provision, and conservatives like Senator Ted Cruz were also speaking out in opposition.

Boehner tried to use the desire of lawmakers to recess for the year as an enticement to support the bill in the House. "If we don't get finished today, we're going to be here until Christmas," he told reporters before the procedural vote.