WASHINGTON -- The House passed a long-term funding bill for the Department of Homeland Security, ending the possibility of a shutdown and abandoning the effort to fight President Barack Obama’s immigration orders. The bill passed 257-167, with all Democrats and fewer than a third of Republicans supporting the legislation. 

After weeks of wrangling and bouncing the bill between chambers, the House ultimately agreed to the Senate version of funding legislation for DHS. The bill now heads to Obama’s desk, and he is expected to sign the legislation. The vote came as House Speaker John Boehner caved to pressure the agency needed to be funded through the remainder of the fiscal year, which ends in September. Boehner had been pressured by the conservative members of his caucus who insisted the funding be tied to a reversal of the president’s orders that provided 5 million undocumented immigrants with legal status. Boehner even cast a vote in favor of the bill, a rarity since the speaker almost never votes on legislation.

Debate on the floor before the House voted took an unusual turn. Instead of Republicans and Democrats splitting the time to speak against each other, it was an intraparty debate for the GOP. Republican members took to the floor to criticize one another. Of the 245 House Republicans, 167 voted against the bill.

A bipartisan majority in the Senate proved to be Boehner’s undoing. Despite his efforts to get the Senate to go along with his plans to pressure Obama on immigration, strong Democratic opposition joined by several Republicans resulted in pushback from the upper chamber. Boehner had resisted allowing a vote on the full-funding trying to utilize procedural tactics that were designed to pressure Senate Democrats to go along with changes in immigration policy. But Boehner’s efforts met bipartisan opposition in the Senate where Majority Leader Mitch McConnell struck a deal with Minority Leader Harry Reid to separate the funding from the immigration fight.

Boehner attempted to get a three-week extension of DHS funding passed last week, but conservatives and Democrats -- for different reasons -- banded together to defeat the legislation. Boehner was left with only a one-week extension, which eroded his ability to keep up the fight and avoid a shutdown of the agency.

Boehner must now deal with the conservative members of his caucus, who have been unhappy with him for years. The intensity has grown, especially as some conservatives have become frustrated Republican control of the Senate hasn’t resulted in more of their bills being sent to the president’s desk. Rep. Thomas Massie, R-Ky., led the conservative opposition to the funding bill on the floor. He made a failed motion to table the legislation, which garnered only 140 Republican votes. 

While conservatives have frequently been able to pressure their fellow members on spending legislation, in this case many Republicans voted in favor of the bill. "We must continue this fight, but we must also allow funding for national security priorities," Rep. Mike Simpson, R-Idaho, said as he called for the vote on the floor.

The White House released a statement on Tuesday evening from President Obama: "To make sure the Americans who protect our country and our people have the resources they need to get the job done, I will sign this bill into law as soon as I receive it."

This story was updated at 8:30 p.m.