BAGHDAD — U.S. troops leaving Syria and heading to neighboring Iraq do not have permission to stay in the country, Iraq’s military said Tuesday as American forces continued to pull out of northern Syria after Turkey’s invasion of the border region.

The statement appears to contradict U.S. Defense Secretary Mark Esper, who has said that under the current plan, all U.S. troops leaving Syria will go to western Iraq and the military would continue to conduct operations against the Islamic State group to prevent its resurgence in the region.

On Tuesday, Esper said he plans to talk to Iraqi leaders to work out details about the U.S. plan to send American troops withdrawing from Syria to Iraq, adding that the U.S. has no plans to have those troops stay in Iraq “interminably.”

Speaking to reporters at Prince Sultan Air Base in Saudi Arabia, Esper said he’ll have a discussion with the Iraqi defense minister on Wednesday. He said the aim is to pull U.S. soldiers out and “eventually get them home.”

Defense Secretary Mark Esper talks to reporters at Prince Sultan Air Base in Saudi Arabia, Tuesday, Oct. 22, 2019, where he saw a Patriot missile battery that the U.S. sent to Saudi to help protect the kingdom against the Iranian threat. (Lolita Baldor/AP)

President Donald Trump ordered the bulk of U.S. troops in Syria to withdraw after Turkish President Recep Tayyip Erdogan made it clear in a phone call that his forces were about to invade Syria to push back Syrian Kurdish fighters whom Turkey considers terrorists.

The pullout largely abandons the Syrian Kurdish allies who have fought the Islamic State group alongside U.S. troops for several years. Between 200 and 300 U.S. troops will remain at the southern Syrian outpost of Al-Tanf.

Angered at feeling betrayed, some residents in areas populated predominantly by Kurds in both Syria and Iraq have pelted the withdrawing troops. On Monday, a U.S. convoy that was driving down an avenue in the Kurdish-dominated city of Qamishly was pelted with potatoes.

× Fear of missing out? Sign up for the Early Bird Brief - a daily roundup of military and defense news stories from around the globe. Thanks for signing up. By giving us your email, you are opting in to the Early Bird Brief.

“Like rats, America is running away,” one man shouted in Arabic at the vehicles.

Near the Iraqi city of Irbil, a small group of young men threw stones at a convoy of U.S. armored vehicles, shouting obscenities as it drove down a main highway, according to a video circulating online.

In a statement, the Iraqi Kurdish regional government said the positive role played by U.S.-led coalition forces in northern Iraq, protecting and assisting its residents, should not be confused with an “unpopular political decision” that has been taken — a reference to Trump’s sudden move to withdraw troops from Syria.

An Iraqi official said his government has told the Americans that they will allow the U.S. forces to pass through, but not to stay.

“They understood that and will clarify that” in the next hours, the official said, speaking on condition of anonymity.

The number of American forces in Iraq has remained small due to political sensitivities in the country, after years of what some Iraqis consider U.S. occupation during the war that began in 2003. It is a potentially explosive issue.

The U.S. currently has more than 5,000 American forces in Iraq, under an agreement between the two countries. The U.S. pulled its troops out of Iraq in 2011 when combat operations there ended, but they went back in after IS began to take over large swaths of the country in 2014.

After the Iraqi government announced victory against IS in 2017, calls for an American troop withdrawal increased amid concerns about America’s long-term intentions, particularly after it withdraws its troops from Syria.

Earlier this year, Trump angered Iraqi politicians and Iranian-backed factions by arguing he would keep U.S. troops in Iraq and use it as a base to strike Islamic State group targets inside Syria as needed. In February, he infuriated Iraqi leaders when he said U.S. troops should stay in Iraq to monitor neighboring Iran.

Some American troops may stay in Syria to guard oil fields, Esper says The U.S. may leave some forces in Syria to secure oil fields and make sure they don’t fall into the hands of a resurgent Islamic State, Defense Secretary Mark Esper said Monday, even though President Donald Trump has insisted he is pulling troops out of the country and getting out of “endless wars.”

Earlier this week, Esper did not rule out the idea that U.S. forces would conduct counterterrorism missions from Iraq into Syria. But he said those details will be worked out over time.

His comments were the first to specifically lay out where American troops will go as they leave Syria and what the counter-IS fight could look like. Esper said he has spoken to his Iraqi counterpart about the plan to shift the estimated 1,000 troops leaving Syria into western Iraq.

The statement by the Iraqi military, however, said that all American troops that withdrew from Syria have permission to enter northern Iraq’s semi-autonomous Kurdish region, and then from there to be relocated out of Iraq.

“These forces do not have any approval to remain in Iraq,” it said. The statement did not specify a time limit for how long the troops can stay there.

Meanwhile, U.S. troops continued to pull out of northern Syria. Reports of sporadic clashes have continued between Turkish-backed fighters and the U.S.-allied Syria Kurdish forces despite a five-day cease-fire agreement hammered out on Thursday between U.S. and Turkish leaders. The cease-fire expires Tuesday night.

Esper has said the troops going into Iraq will have two missions.

“One is to help defend Iraq and two is to perform a counter-ISIS mission as we sort through the next steps,” he said, using an alternative acronym for the Islamic State group. “Things could change between now and whenever we complete the withdrawal, but that’s the game plan right now.”

Karam reported from Beirut. Associated Press writer Lolita C. Baldor in Saudi Arabia contributed to this report.