WASHINGTON — The fight over funding the Department of Homeland Security that began with Republicans thundering about a lawless president abusing power to change immigration policy ended with a quiet capitulation Tuesday when the House voted to fund the agency and avert a partial shutdown.

In the end, Speaker John A. Boehner was forced to build a majority on Democratic votes to pass the bill, 257 to 167, with just 75 Republican supporters. But although the uprising among conservatives burned hot into the week, there was no suggestion that Mr. Boehner’s leadership was imperiled. Instead, many Republicans expressed a sense of resigned relief.

The bill, which President Obama will sign, dealt only with an appropriation for the department. Republicans agreed to drop their push for provisions that would have gutted Mr. Obama’s executive actions on immigration.

“How did we end up with kind of a slow demise, you mean, even after a very hefty kind of rhetoric?” asked Representative John Fleming, Republican of Louisiana. “Well, apparently that’s the way it’s done around here. I don’t agree with it.”

Representative Mick Mulvaney, Republican of South Carolina, called the outcome “an unmitigated loss for conservatives.” But he, like many other members who voted against the bill, also said there had been no serious discussion in the conference about trying to remove Mr. Boehner from his speakership.

Mr. Boehner’s decision, surprising in its timing, reduced the potential for the political fallout that Republicans would have faced if the department’s operations were halted in a way that harmed public safety. The top three House Republicans — Mr. Boehner of Ohio, as well as Representative Kevin McCarthy of California, the majority leader, and Representative Steve Scalise of Louisiana, the whip — voted for the bill.

In a closed meeting of Republicans on Tuesday morning, Mr. Boehner told members that he was “as outraged and frustrated as you at the lawless and unconstitutional actions of this president,” according to one person who was in the room, speaking on the condition of anonymity to discuss a private session. Mr. Boehner added that he thought the decision was “the right one for this team, and the right one for this country.”

Mr. Boehner’s turnabout came after his leadership team had a humiliating setback on Friday, narrowly averting a partial shutdown of the department after his more conservative members revolted against a Republican plan to pass a three-week funding measure.

The House leadership had hoped that the short-term measure would provide it with more time to pressure the Senate to take up a bill that passed the House in January. That legislation would have funded the agency but also would have gutted the legal protections that Mr. Obama provided through executive actions to as many as five million undocumented immigrants, including children.

But the backlash against the near shutdown of the agency was swift, with Republicans shouldering most of the criticism — from Democrats, from the news media and even from many in their own party. The Republican leadership — which had promised to govern effectively, without the threat of shutdowns, after gaining control of both chambers of Congress in the November elections — had now failed its first major governing test, and it realized it needed to move beyond the current fight.

This week, a Wall Street Journal editorial called the recalcitrant Republican conference “Cliff Marchers,” warning that the impasse was a choice between “recognizing political reality, or marching off a cliff to almost certain failure.”

On Tuesday morning, Mr. Boehner presented three possible solutions to his members — a partial shutdown of the agency, another short-term measure that would postpone the fight or a “clean” funding bill with no immigration provisions. His members quietly accepted full funding.

“You would have thought we were talking about renaming a post office,” said Representative Peter T. King, Republican of New York, who has long pushed to fund the department with no strings attached.

“I do give John Boehner credit for standing strong through all this and guiding us,” Mr. King said. “A certain group takes the party in this crazy direction, and we end up coming back and doing the right thing in the end, with just political damage done along the way. Thank God there was no governmental damage done along the way.”

The timing of the vote was auspicious, and strategic. By bringing up the legislation on the day that Prime Minister Benjamin Netanyahu of Israel addressed a joint meeting of Congress, Mr. Boehner capitalized on the spectacle and the political cushion from his members, who were pleased with the way he stood up to the White House in inviting Mr. Netanyahu to speak.

After Mr. Boehner presented the plan, he asked for questions but received none. Then, Representative Doug Lamborn, Republican of Colorado, stood up to thank the speaker for standing strong in the face of White House attacks on Mr. Netanyahu, and the conference gave Mr. Boehner a standing ovation.

But not every lawmaker seemed pleased with the outcome. Representative Tim Huelskamp, Republican of Kansas, said that the speaker had “just caved in” and that his strategy had clearly failed.

“Tooth-and-nail ended in here today,” he said, referring to Mr. Boehner’s promise to fight the president’s executive actions on immigration “tooth and nail.”

“Everybody kind of must have laughed to themselves when he said he’s going to listen and work with all members in the future. I don’t think a soul in there believed that story.”

Similarly, Representative Steve King, Republican of Iowa and an outspoken immigration opponent, said that he was frustrated with Tuesday’s vote, but that his conference had succumbed to “the exhaustion of the relentless push and the strategic moves that were made in the Senate, and also in the House.”

“I think the mood of this thing is such that to bring it back from the abyss is very, very difficult,” Mr. King said.

Tuesday’s reversal by House Republicans also reflected a win for congressional Democrats, who had opposed any bill that did not fully fund the agency with no additional provisions, forcing Republicans into a jam — and, ultimately, into passing a clean bill, as Democrats had demanded.

Representative Charlie Dent, Republican of Pennsylvania and a moderate, also said the funding bill was a win “for the governance wing of the party.”

“If we are going to spend all of our time and energy moving from cliff to cliff, crisis to crisis, shutdown to shutdown, it’s going to prevent us from doing the other necessary work the American people expect us to do,” Mr. Dent said. “If we can get that right, then we can start dealing with other policy issues, whether it be trade, transportation, tax reform, whatever.”