WASHINGTON ― U.S. Secretary of State Rex Tillerson said Monday night that American forces would hypothetically stay in Iraq in order to defeat the Islamic State group, even if the government in Baghdad requests the U.S. leave.

Tillerson, appearing with Secretary of Defense Jim Mattis in front of the Senate Foreign Relations Committee, indicated American forces have the right to stay in Iraq under the 2001 and 2002 Authorizations for the Use of Military Force (AUMF), a long-standing justification for military action around the globe, until the fight against ISIS is concluded.

The statement came up in response to a question from Sen. Tom Udall, D-N.M., who asked “If U.S. forces are told to leave, will we depart Iraq or will be stay uninvited as our forces are doing in Syria, and under what legal authority will they remain?”

Responded Tillerson: “We will remain in Iraq until ISIS is defeated and we are confident that ISIS has been defeated.”

When Udall pushed again on what legal authority that would occur, Tillerson responded by citing the 2001 and 2002 AUMFs.

However, the secretary stressed that “we are there also at the invitation of the Iraqi government and that [Iraqi Prime Minister Haider al-Abadi] has given to me no indication he is in any particular hurry to have us depart.”

Mieke Eoyang, vice president of the national security program at the Third Way think tank, called the idea of staying in Iraq against the desire of Baghdad “insanity.”

“At that point, the U.S. would be considered an invading force by the Iraqis and would become a target not only of ISIS, but the Iraqi Security Forces,” said Eoyang, a longtime Democratic staff member on the Hill.

“That’s from a practical perspective. From a legal perspective, they’re on even shakier ground. ISIS didn’t exist when they passed the 2001 AUMF and the 2002 AUMF was to enforce U.N. Security Council resolutions. They don’t have that here. Tillerson needs to go talk to Mattis and his lawyer before he commits to that position.”

Kori Schake, a fellow with the Hoover Institution who worked at both the National Security Council and the Defense Department during the George W. Bush administration, said it is “unfortunate Secretary of State Tillerson gave the impression we would remain in Iraq without Iraqi approval.”

But, Schake thinks Tillerson may have inadvertently stumbled into that stance. Tillerson’s response came as part of a broader question from Udall about the role of Iran-backed militias in Iraq. Last week during a visit to Iraq, Tillerson called for Iran-backed militias to either turn down arms or leave the country.

“I honestly think he was trying to clean up his previous awkward suggestion Iraqi Shi’ia militia ‘go home’ to Iran, and bungled into another round of making news that will require cleaning up,” Schake said.

Asked for clarification on Tillerson’s remarks, a State Department spokesman said the department doesn’t deal in hypotheticals and deferred to the secretary’s comments.

Pentagon spokeswoman Dana White said she would “associate us” with Tillerson‘s comments, adding “I won’t answer hypotheticals. We are in Iraq to defeat ISIS and as [Tillerson] said we are there by invitation.”

A senior Iraqi diplomat, informed of Tillerson’s comments, told Defense News that “the U.S. forces are at the official request of the Iraqi government; the effectiveness of their support and the coalition allies’ to the Iraqi Security forces is gratefully acknowledged. The Iraqi government is committed to maintaining the course of cooperation with our allies until the ultimate defeat of ISIS, in such a way that ensures that there is no sequel to this terrorist group.”

This story was updated 10/31/17 at 11:59 AM EST with comment from the Iraqi diplomat.