A $1 trillion spending bill keeps most of the federal government funded through September. Here, The Post's Ed O'Keefe points out a few of the most notable components of the legislation. (Davin Coburn/The Washington Post)

Congress managed to narrowly avoid another government shutdown crisis Thursday night when the House approved a $1.1 trillion spending package to keep most government agencies operating through next summer.

The 219-to-206 vote came with less than three hours to go until government funding expired. The result capped a long and acrimonious day in which House Democrats nearly upended the entire package, which was backed by President Obama. The showdown exposed some of the dynamics on Capitol Hill in which the most liberal Democrats replaced the most conservative Republicans as significant obstacles to passing difficult fiscal legislation.

Senators late Thursday approved a two-day extension of current funding in order to give them more time to work through arcane procedural rules, pass the bill and cap the least productive congressional session in modern history.

Passage of the legislation will be a victory for congressional Republicans, who were eager to wipe the slate clean of a host of unresolved matters before taking full control of Capitol Hill next year. The spending agreement also sets up what promises to be a heated three-month battle with Obama over the future of the nation’s immigration policy.

The tumult surrounding the bill surfaced in the House around midday Thursday, when every Democrat present voted against a procedural motion to begin debate. With the effort in danger of failing, Republican leaders convinced one outgoing Republican member to switch his vote and allow debate to begin.

The White House tried quickly to come to the rescue, announcing Obama’s support for the legislation, even as it criticized provisions in the 1,603-page bill that would weaken some Wall Street regulations and loosen campaign donation limits. A concerted lobbying effort involving Obama, Vice President Biden and other top officials eventually helped secure enough support.

But House Minority Leader Nancy Pelosi (D-Calif.) sharply rebuked the president in a floor speech, charging that Democrats were “being blackmailed” into passing the measure because the shutdown deadline was so close.

“I’m enormously disappointed that the White House feels that the only way they can get a bill is to go along with this,” she said. “That would be the only reason I think they would say they would sign such a bill.”

Pelosi’s outrage was shared by a majority of Democrats, who were also infuriated by several policy changes tucked inside the omnibus agreement released late Tuesday.

When they saw the text Wednesday morning, rank-and-file Democrats lashed out at provisions undoing a signature piece of the Dodd-Frank financial regulatory overhaul and allowing banks to more easily trade the investments known as derivatives. The financial overhaul enacted in
2010 ranks among the biggest
domestic achievements of the Obama presidency and the
formerly Democratic-controlled Congress.

Another controversial part of the bill would permit a wealthy couple to give three times the current donation limits to the national political parties.

At a closed-door leadership meeting Thursday morning, Pelosi and her team said they would try again to extract concessions from House Speaker John A. Boehner (R-Ohio). Exiting the meeting, Rep. Charles B. Rangel (D-N.Y.) said Pelosi was telling members to “keep your powder dry.” Summarizing the tug felt by many Democrats, the 84-year-old Rangel said that he didn’t like the bill, “but I absolutely don’t like shutting down the government.”

Pelosi and Boehner spoke twice by telephone during the day, but Pelosi’s attempts to make last-minute changes were rebuffed, according to aides to both leaders.

In addition to Obama and Biden, Jeffrey Zients, chairman of Obama’s National Economic Council, and Shaun Donovan, the White House budget director, phoned wavering Democrats. So did Democratic members of the Senate Appropriations Committee, including Chairman Barbara A. Mikulski (Md.) and Sen. Christopher A. Coons (Del.), according to lawmakers who received calls.

White House Chief of Staff Denis McDonough also made an in-person plea for support during a closed-door meeting in the basement of the U.S. Capitol on Thursday night. Asked about the Wall Street and campaign finance provisions in the bill, McDonough told the Democrats, “We learned about these [two] provisions when you did,” according to aides in the room.

Rep. Steve Israel (D-N.Y.), a close Pelosi ally, said that McDonough had tried to assuage Democratic concerns by arguing that the economy needs the “certainty” and “consistency” of a one-year bill. But he said many rank-and-file members vocally expressed their concerns with the bill.

Pelosi, Rangel, Israel and 136 other Democrats voted against the bill, while 57 Democrats and 162 Republicans voted in favor.

Minority Whip Steny H. Hoyer (D-Md.) led Democrats in favor of the bill and said that while it was far from perfect, “on balance, I thought the bill ought to pass.”

The wave of Democratic opposition in the House appeared backed in part by Sen. Elizabeth Warren (D-Mass.), a popular figure on the left who voiced concern on Wednesday that the bill would sharply increase the influence of wealthy campaign donors. She said the bill reflected “the worst of government for the rich and powerful.”

Others, such as Sen. Bernard Sanders (I-Vt.), who is traveling to Iowa on Monday as he mulls a 2016 presidential bid, said that he would vote against the bill. While it includes increased funding for veterans’ health care — one of Sanders’s top priorities — he called the changes in Wall Street regulations “totally absurd.”

But moderate Democrats who backed the bill faulted Warren for stirring up trouble on the other side of the Capitol.

“That’s what you do when you run for president,” said Rep. James P. Moran (D-Va.), a senior member of the Appropriations Committee. “You get out front knowing that there are a whole lot of people who are not going to let anyone get to the left of them.”

The Democratic split capped a rare political role reversal as Republicans spent most of Thursday on the sidelines.

Exiting Boehner’s office just as House Democrats began meeting Thursday night, Rep. Robert Pittenger (R-N.C.) said Republicans would pass the bill despite Democratic disagreements.

“I hope we don’t have to change anything to it,” he said, adding later: “Let’s go govern.”

Republican support grew throughout the day despite the objections of dozens of conservatives that the legislation would not punish Obama hard enough for using his executive authority to change immigration policy.

Rep. Bill Flores (R-Tex.), the incoming chairman of the conservative Republican Study Committee, said he would be against the bill because “my constituents are telling me that they’re against it. I think that it would be hard to totally stop the president’s unlawful amnesty action, but I think we could try a little bit harder to fix it.”

Conscious of conservative concerns about immigration, Majority Whip Steve Scalise (R-La.) made a point of coming off the House floor to tell reporters that the bill would launch a showdown with the Obama administration on immigration reform early next year.

“That battle is going to be very viciously fought, not only in the House but in the Republican Senate,” he said before quickly hustling back on to the floor.

Boehner especially was at ease as the final vote began. As he headed to the floor, he stopped and told reporters: “I’m a happy warrior.”

Sean Sullivan, Paul Kane, Steven Mufson and Aaron C. Davis contributed to this report.