The House voted Tuesday to fund the Department of Homeland Security, ending a months-long impasse over President Obama’s immigration policies and averting a weekend shutdown at the agency.

But it also highlighted once again the tenuous power Boehner enjoys over his conference.

The spending bill cleared the House on a 257-167 vote only because of the unanimous support of House Democrats.

All 167 “no” votes came from Republicans — more than twice as many as the 75 who supported the bill. Out of 21 House GOP committee chairmen, 12 broke with leadership and voted against the clean funding bill. Nine voted “yes.”

The $40 billion bill keeps the DHS funded through the fiscal year, ending Sept. 30, but is stripped of GOP-favored provisions aimed at halting Obama’s controversial executive actions on immigration. The so-called clean funding bill had passed the Senate earlier; it now goes to Obama, who has already vowed to sign it.

Supporters cheered the move, saying it would finally let the GOP move on to its agenda.

“I’ve said all along we need to govern responsibly, and this is an important step,” said freshman Sen. Cory Gardner (R-Colo.), who had spent weeks urging his former House colleagues to back a clean funding bill.

The DHS fight exposed deep fissures between House Republicans, who wanted to take a more aggressive stance, and Senate Republicans, who argued early on that Obama had a stronger hand in the standoff and would ultimately prevail.

Conservatives said they weren’t surprised Boehner capitulated to Democrats. But they still voiced frustration that GOP leaders hadn’t put up a stronger fight in Congress.

“I believe this is a sad day for America,” Rep. Matt Salmon (R-Ariz.) said on the House floor during a vigorous debate before the vote. “If we aren’t going to fight now, when are we going to fight?”

The Speaker spelled out his plans — and the political reality — in a GOP caucus meeting at the Capitol Hill Club on Tuesday. He told rank-and-file members the House had voted to fund the DHS and stop Obama’s executive actions but that Senate Democrats repeatedly had blocked the bill from moving forward, according to a source in the room.

It’s unlikely another short-term measure could have passed Congress, Boehner said. And shutting down the nation’s top agency charged with fighting domestic terror was out of the question.

“With more active threats coming into the homeland, I don’t believe that’s an option,” Boehner told his members. “Imagine if, God forbid, another terrorist attack hits the United States.”

Republicans’ best shot to stop Obama’s immigration policies, Boehner explained, is now in the courts. A federal judge from Texas has temporarily halted the policies from taking effect, ruling that the president’s actions violated federal law. The administration has appealed.

“I am as outraged and frustrated as you at the lawless and unconstitutional actions of this president,” Boehner said. “I believe this decision — considering where we are — is the right one for this team, and the right one for this country.

“The good news is that the president’s executive action has been stopped, for now. This matter will continue to be litigated in the courts, where we have our best chance of winning this fight.”

Rep. Mike Simpson (R-Idaho), a close ally of Boehner’s, made the motion Tuesday to use an obscure House rule to bring the Senate-passed funding bill to a House vote.

He was also one of three floor managers on the bill, something highly unusual in the House. Typically there is only one floor manager per party.

Simpson managed debate for Republicans; Rep. Nita Lowey (N.Y.) for Democrats; and Rep. Thomas Massie (R-Ky.) for hard-line conservative members.

Simpson blasted the conservatives’ strategy as a path destined to fail. He pointed out the DHS funding bill doesn’t contain money for processing the executive actions in the first place, because those are funded by fees.

“What it will lead to is a closedown of the Department of Homeland Security. And that is not a victory. That is dangerous,” he said.

Congressional Republicans have wrestled for the past three months over how to respond to Obama’s executive actions. In the November lame-duck session, the president announced new initiatives that would shield as many as 5 million people from deportation and give many of them work permits.

In December, Republicans funded the entire government through September except the DHS, which they chose to only fund through February. Republican leaders believed once they controlled both chambers of Congress, they would be in a stronger position to torpedo the executive orders.

The House first passed a new funding bill in January with provisions that would reverse Obama’s immigration policies from 2011, 2012 and 2014. Senate Democrats, despite being in the minority, blocked it four times from reaching the Senate floor.

Some Republicans saw an exit ramp when the federal judge temporarily halted Obama’s 2014 orders in February, but conservatives in the House insisted on keeping up the fight.

Boehner didn’t immediately accept that option, and tried to produce a conference agreement with Senate Republicans. That plan spiraled out of control last Friday when a three-week DHS funding bill failed after conservatives and Democrats voted against it in a humiliating defeat for GOP leaders.

To prevent a partial DHS shutdown just hours before the deadline, Boehner had to agree to a deal with Pelosi on a one-week funding bill. Pelosi said she agreed to the one-week funding because it would lead to a vote this week on longer-term funding for DHS.

“These cliffs are disastrous for all of us. Time to move on,” said centrist Rep. Charlie Dent (R-Pa.), who has long been critical of the party’s strategy on the issue.