Despite their inability to agree on the economy or much else, Republican presidential candidates spoke with one voice in reaction to President Obama’s announcement of a full U.S. withdrawal from Iraq this year.

They were against it.

It was an “astonishing failure” that risked all the gains made “through the blood and sacrifice” of thousands of Americans, former Massachusetts Gov. Mitt Romney said.

Texas Gov. Rick Perry said he was “deeply concerned” that Obama had put “political expediency ahead of sound military and security judgment.” Rep. Michele Bachmann (R-Minn.) cited it as another example of the president’s foreign policy weakness, and Jon Huntsman, Obama’s former ambassador to China, called it a “mistake.”

Herman Cain let stand his assessment of last weekend, in which he announced that withdrawals from Iraq and Afghanistan were “a dumb thing to do.”

The agreement to withdraw all U.S. forces from Iraq by Dec. 31 was originally reached with the Iraqi government by the Bush administration in 2008. Obama said early this year that he would consider leaving a contingent of unspecified size behind to train and aid the Iraqis if their government requested it.

But Iraqi Prime Minister Nouri al-Maliki was unable to persuade segments of his own governing coalition to agree, and negotiations with the administration fell apart last week when Iraq insisted it would not grant U.S. forces immunity from prosecution there, unlike every other country where they are stationed abroad.

Obama’s Iraq announcement seemed to provide some breathing room for his political opponents, many of whom felt compelled earlier in the week to hail the fall of Libyan strongman Moammar Gaddafi with help from a U.S. intervention they had initially criticized as either an unnecessary risk or too tepid a commitment.

The field had been set to denounce the Iraq deal for weeks, as administration officials began to hint that agreement with the Maliki government might not be possible.

Last month, a list of 43 conservative foreign policy notables — many of them Bush administration architects of the Iraq war, advisers to the Romney camp or both — wrote to Obama urging him to “ensure that a significant U.S. military presence remains in Iraq after 2011 to assist the Iraqi government.”

At the time, the administration had indicated it was considering leaving about 3,000 troops behind, a force that the letter said was “significantly smaller than what U.S. military commanders on the ground have reportedly recommended and would limit our ability to ensure that Iraq remains stable and free from significant foreign influence,” specifically from neighboring Iran.

Although some military commanders had privately voiced concern about the abilities of the Iraqi armed forces, many considered the lack of an immunity agreement a deal-breaker.

Faced with public opinion that has long been in favor of a complete withdrawal from Iraq, Romney, Perry, and Bachmann simultaneously charged Obama with trying to curry political favor at home and failing to strike a deal with the Iraqis.

“The unavoidable question is whether this decision is the result of a naked political calculation or simply sheer ineptitude in negotiations,” Romney’s statement said.

Obama’s campaign headquarters immediately pushed back. While “the president kept his pledge to the nation to end the war in Iraq in a responsible way,” press secretary Ben LaBolt said in a statement released by Obama for America, “Mitt Romneydidn’t lay out a plan to end the war in his foreign policy agenda . . . but he is apparently willing to leave American troops there without identifying a new mission.”

Romney’s foreign policy experience, LaBolt said in an indication of a future Obama attack line, “is limited to his work as a finance executive shipping American jobs overseas.”

Other Republican leaders took more of a middle ground, hailing the end of the war and the return home of the troops, while worrying that trouble may be looming.

The war had been won by U.S. forces, “under the strategy developed and implemented by our generals, and the leadership of both President Bush and President Obama,” House Speaker John A. Boehner (R-Ohio) said. “While I’m concerned that a full withdrawal could jeopardize those gains, I’m hopeful that both countries will work together to guarantee” a stable Iraq and strong U.S. partnership.”

Staff writer Nia-Malika Henderson contributed to this report.