WASHINGTON – After hours of wrangling over votes, the House passed a $1.1 trillion spending bill to avoid a government shutdown. For hours on Thursday, it appeared the bill was lacking the votes needed to pass. But Republican leadership was able to garner enough support after putting the bill on the floor.

The bill passed 219 to 206 with bipartisan support -- and bipartisan opposition: 67 Republicans opposed the spending bill and 57 Democrats supported it. The bill now heads to the Senate, where it is expected to pass before Sunday. 

(Read the full text of the bill here.)  

The House and Senate approved a two-day continuing resolution before 11 p.m., sending the stopgap measure to the president with an hour to spare.  President Barack Obama signed it shortly after midnight. 

It was a victory for House Speaker John Boehner and Obama -- yes, they were on the same side in this fight -- who worked into Thursday evening trying to rally enough votes to ensure passage. It opened up a Democratic intraparty fight, with House Minority Leader Nancy Pelosi opposing the president.

“With a bipartisan vote, the House has passed a responsible bill to keep the government running and address the American people’s priorities," Boehner said. "This measure puts us on track to save taxpayers more than $2.1 trillion while protecting jobs and supporting our national defense."

With only hours left before the Thursday night deadline to fund the government, the process appeared to have come unhinged. Minutes before the vote was supposed to be taken mid-afternoon, the House went into recess. The abrupt end of the debate signaled that leadership wasn’t confident there were enough votes.

The bill's opponents delayed the passage and brought high drama to the day, but ultimately couldn’t produce enough votes to block the bill. Many Democrats voted against the bill because it contained provisions they couldn’t swallow, including changes to the Wall Street reform Dodd-Frank law and increases in campaign finance donation limits. Conservative Republicans voted against the bill because they were frustrated that it wasn’t aggressive enough in going after Obama’s executive orders on immigration.

The decision to move forward on the bill appeared to be Republican leadership taking its chances after an afternoon and evening of prodding, coaxing and wrangling. Letting the bill die on the floor would make clear where everyone stood, and allow GOP leaders to move forward with another option.

Instead, the House shocked many by passing the legislation and sending it to the Senate.

For days, Boehner had been confident the bill would have enough bipartisan support to gain approval in the House. But on Thursday afternoon it quickly became clear that the support might not be there.

Obama endorsed the legislation. When it became clear the bill was still in trouble with Democrats, he began making phone calls.

But many of the Democratic House leaders held strong in opposition of the bill. Pelosi insisted that the bill was bad for Democrats and chastised the White House for backing it. Massachusetts Senator Elizabeth Warren also spoke out strongly against it. 

House Democrats met for more than three hours on Thursday night to discuss the bill among themselves. White House Chief of Staff Denis McDonough attended to try to persuade members to support the bill.

Now fears of a government shutdown can recede. The cromnibus funds most of the government through September 2015.