House Republicans banded together on Tuesday to shelve an effort to impeach Defense Secretary Pete Hegseth, shielding him from a damaging rebuke and a potential ouster after their party suffered crippling losses in an election that turned on voters’ discontent about the Iran war.

The action spared Republicans a vote on whether to impeach Mr. Hegseth on eight separate charges, including violating the Constitution to wage war in Iran and elsewhere without congressional authorization, flouting laws to mitigate civilian casualties and abusing his power by retaliating against a senator for public statements.

The vote was 211 to 204 to refer the charges to a committee, which would allow Republicans to slow the process indefinitely. Only one Republican, Representative Thomas Massie of Kentucky, who spearheaded the effort, voted with Democrats against doing so.

President Trump said the vote was an “exoneration” of Mr. Hegseth and warned that Democrats “must be stopped” from what he said was weaponization of government.

The outcome was an unexpected reprieve for Mr. Hegseth, one of President Trump’s most outspoken and combative cabinet members and the public face of the war with Iran. Democrats could still move to impeach him next year when they assume power, but have so far not indicated whether they will try to do so.

His conduct has, at times, drawn bipartisan criticism from members of Congress, and his standing in the administration was further thrown into question following sweeping Republicans losses in the midterm elections, in which voters’ discontent about the war was a major factor. It had not been clear whether G.O.P. lawmakers, including several who were unexpectedly defeated or won re-election far more narrowly than they anticipated, would rally to support him.