BEIRUT — Iraq's prime minister met with the U.S. ambassador Monday to discuss relations that have been strained by U.S. airstrikes on Iraqi soil and a parliamentary call in Baghdad for thousands of American troops to leave.

Prime Minister Adel Abdul Mahdi and Matthew Tueller, the U.S. ambassador to Iraq, described the need for “joint cooperation” on any withdrawal, according to a statement from the prime minister’s office.

In a letter to the Iraqi military, the U.S. military in Baghdad said Monday that it would be repositioning its troops in preparation for a possible withdrawal. But senior U.S. defense officials said the Trump administration has made no decision to depart.

Unlike some other deployments stretching back to 2008, U.S. troops in Iraq are not operating under a conventional status-of-forces agreement approved by the Iraqi parliament, according to experts.

Instead, the current military presence is based on an arrangement dating from 2014 that’s less formal and ultimately based on the consent of the Iraqi government, which asked the parliament on Sunday to pass urgent measures to usher out foreign troops.

And so, with Abdul Mahdi’s stroke of a pen, the 5,000-strong force could technically be asked to leave.

“The current U.S. military presence is based [on] an exchange of letters at the executive level,” said Ramzy Mardini, an Iraq scholar at the U.S. Institute of Peace.

The terms outlined in those letters have not been made public.

“We have a very extraordinarily expensive air base that’s there. It cost billions of dollars to build,” Trump said on Air Force One as he returned to Washington from Florida on Sunday.

“We’re not leaving unless they pay us back for it,” he said, apparently in reference to Ain al-Asad, a base originally built under Saddam Hussein’s government, but later extended by the United States.

Trump’s decision to order the killing of Iran’s most influential military figure, Maj. Gen. Qasem Soleimani, on a small road leaving the Baghdad airport, has set off a firestorm in Iraq, angering politicians and intensifying militia threats against U.S.-led coalition bases across the country.

The 81-country coalition began its mission in June 2014 as Islamic State fighters coursed through Iraq and Syria, seizing land that they would come to call their caliphate, and beginning a genocide against Iraq’s Yazidi religious minority.

“If the prime minister rescinds the invitation, the U.S. military must leave, unless it wants to maintain what would be an illegal occupation in a hostile environment,” Mardini said.

With the Islamic State largely defeated, coalition troops now serve in a mostly advisory capacity. U.S. commanders say that the mission remains crucial to preventing the group’s resurgence. The coalition said Sunday that it had been forced to suspend training activities and was focusing instead on simply keeping its personnel safe.

Weeks earlier, senior commanders from the U.S.-led coalition had told reporters they were worried the Trump administration would enact a hasty withdrawal of U.S. troops from Iraq, imperiling a training mission that had bolstered the ability of Iraqi forces to fight the Islamic State.

Speaking on the condition of anonymity because they were not authorized to brief the press, the military commanders said that the Iraqi army had made significant strides since it nearly fractured in the face of an Islamic State takeover of swaths of northern Iraq in 2014.

“This is not the ISF of Mosul,” said one commander stationed in Habbaniyah, in western Iraq, using an acronym for Iraqi security forces. In June 2014, Iraqi units collapsed as Islamic State militants entered Mosul.

Still, commanders involved in training Iraqi troops said that challenges remain — and that security forces struggle to develop trust with local populations in areas affected by the fighting. Islamic State militants could exploit this lack of trust, they said, and make inroads in regions they were once forced to flee.

“As long as we’re here, it provides stability and deterrence,” said one commander who trains Iraqi forces in Taji, a military complex north of Baghdad.

“It’s a generational fight,” he said.

But by Sunday, the calculus had changed.

Addressing Iraq’s parliament in its wood-paneled chamber, Abdul Mahdi urged lawmakers to take “urgent measures” to force the withdrawal of foreign troops. Shortly afterward, the body passed a nonbinding resolution to that effect, and Abdul Mahdi’s office said that legal experts were drawing up a timetable for the pullout.

With Iraqi law ambiguous, experts suggested that the prime minister’s most likely approach would involve notifying the United States of the prevailing mood in the country, while also affording the Trump administration time to make an exit plan.

“So, give them enough time to consider if they have options to de-escalate, to try to improve the situation,” said Sajad Jiyad, managing director of the Baghdad-based Bayan Center think tank. “He could give them enough notice . . . perhaps he will not need to ask them to leave.”

Among legal experts, Sunday’s parliamentary vote was interpreted as advisory but crucial, providing political cover for a prime minister who has been operating in a caretaker capacity since mass protests forced him to resign in November. It was, Jiyad said, “to make sure that this decision is not legally challenged” and to demonstrate which way political winds are blowing.

“There is no law required to kick the U.S. military out because a law did not establish their presence,” Mardini said. “Baghdad has demonstrated its signal to Washington that the presence of the U.S. military is no longer wanted in Iraq. Since parliament is responsible for determining who is the next prime minister, it’s hard to imagine that individual going against the parliament’s vote.”