(Bloomberg) -- Congress averted a partial shutdown of the U.S. Department of Homeland Security with only two hours to spare by passing a stopgap funding bill that punts a fight over immigration into next week.

The House of Representatives, with support from Democrats, voted 357-60 on Friday for approval. The Senate passed the bill by a voice vote. President Barack Obama signed the measure into law.
Hours earlier, the House failed to pass a three-week spending measure because 52 of Speaker John Boehner’s majority Republicans refused to support it.
“It’s no way to govern the nation and the American people deserve better,” House Appropriations Chairman Hal Rogers said to boos from some lawmakers before the late-night vote. Nevertheless, the Kentucky Republican said, “It’s the 11th hour and we must act.”
Funding for Homeland Security operations was set to expire at midnight on Friday. Without new spending, thousands of employees would have been furloughed or required to work without pay.
The House wants to use the Homeland Security funding bill to block Obama’s November orders that shielded about 5 million undocumented immigrants from deportation.
The one-week extension ensures that the immigration issue will continue to dominate a congressional calendar that Republican leaders wanted to fill with debate over policy priorities including job creation, health-care policy and curbing business regulations.

Latino Voters

Instead, Republicans are mired in an immigration debate that risks alienating Latino voters ahead of the 2016 presidential and congressional elections. It’s a policy confrontation the party can’t win while Obama is in the White House. He has threatened to veto any reversal of his orders.
The one-week bill, H.R. 33, carries the shutdown fight into next week when Israeli Prime Minister Benjamin Netanyahu will address Congress on security issues.
The measure, which extends funding only through March 6, was backed by 183 Republicans and 174 Democrats. Voting no were 55 Republicans and five Democrats.
Among the Republicans opposing the bill was Representative Mick Mulvaney of South Carolina, who accused Boehner of “unwillingness to challenge” Senate Minority Leader Harry Reid, a Nevada Democrat.

Senate Vote

Democrats oppose tying agency funding to immigration policy. The Senate, led by Republicans like the House, voted Friday to fund the agency through September without addressing immigration.
House Minority Leader Nancy Pelosi urged members of her party to support the extension of Homeland Security funding.
“Your vote tonight will assure that we will vote for full funding next week” for the agency, Pelosi said in a letter to colleagues.
Boehner spokesman Michael Steel said, though, that there was no promise to Democrats that there would be such a vote next week. Representative Steve King, an Iowa Republican, warned after the vote that if Boehner were to bring a full-year funding bill without the immigration language to the floor next week, his speakership could be in jeopardy.
The 203-224 vote earlier Friday that defeated a three-week funding bill was a stunning embarrassment for Boehner of Ohio.
The confusion over Homeland Security spending followed episodes last month when Boehner had to pull a border-security bill and an anti-abortion measure from the floor for lack of support.

Speaker Election

In the 2015 session’s opening moments on Jan. 6, Boehner was a target of Republican opposition, as 24 of his party members voted for someone else to be speaker. He won the election, though with votes from less than half of the full House membership.
Representative Walter Jones, a North Carolina Republican who opposed Boehner’s election as speaker, said House leaders “should have known” the extent of opposition to the three-week funding bill within their party.
“You have to be in touch with the ground forces before you attack and that’s one thing I think has been missing for a long time,” Jones said.

House Chaos

The vote was left open for about 45 minutes as chaos reigned. Republican vote-counters huddled at the leadership table going over printouts of the defectors. Majority Leader Kevin McCarthy of California gripped his forehead as if he had a pounding headache.
Republican Conference Chairwoman Cathy McMorris Rodgers of Washington could be seen gesticulating at defector Raul Labrador of Idaho as Democrats chanted that the vote should be ended.
The defeat was an expression of anger by Republican conservatives who say their leaders traded away their leverage to force Obama’s hand on immigration when they agreed in December to fund the rest of the government through September.
“Our leadership set the stage for this,” said John Fleming of Louisiana. “They didn’t want to do the battle” in December. “That’s when they had the best chance and opportunity,” he said.
“They said they would fight tooth and nail,” Fleming said, “and yet we didn’t really see much effort.”
Representative Devin Nunes, a California Republican who voted for the short-term spending bill, said conservatives were undermining their goal of reversing Obama’s immigration orders.

‘The Battlefield’

“You can’t say you want to fight and then not understand tactically how to fight,” Nunes said. “You’ve got to stay on the battlefield,” which is what the three-week spending bill would allow, he said.
A stopgap funding bill gives lawmakers more time to argue over House Republicans’ demand to block Obama’s November immigration orders.
“The Republican Congress has shown that it simply cannot govern,” Reid said in a statement. He repeated his stance that the House has the votes, with Democratic support, to pass the Senate bill that would fund Homeland Security through September with no restrictions on immigration.

Funding Impasse

The funding fight comes less than two months after Republicans took control of both chambers of Congress. Senate Majority Leader Mitch McConnell, a Kentucky Republican, has said the party must show that it can govern and that there will be no government shutdowns like the one in October 2013.
McConnell decided the Senate would consider blocking Obama’s immigration orders in a separate bill, which is backed by Republicans and opposed by most Democrats. He scheduled a procedural vote on that measure for Monday.
That 16-day partial shutdown of the U.S. government was caused by an unsuccessful Republican effort to defund Obamacare.
Homeland Security Secretary Jeh Johnson said Thursday a partial shutdown of his agency would require 30,000 Homeland Security employees to be furloughed and 170,000 essential personnel to keep working without pay.
The Homeland Security Department includes the Coast Guard, Secret Service, Customs and Border Protection, Transportation Security Administration and the Federal Emergency Management Agency.
To contact the reporters on this story: Erik Wasson in Washington at ewasson@bloomberg.net; Heidi Przybyla in Washington at hprzybyla@bloomberg.net; Billy House in Washington at bhouse5@bloomberg.net
To contact the editors responsible for this story: Jodi Schneider at jschneider50@bloomberg.net Laurie Asseo, Justin Blum