BAGHDAD — US troops withdrawing from northeastern Syria to Iraq are “transiting” and will leave the country within four weeks, Iraq’s defense minister said Wednesday.

Najah al-Shammari made the remarks to the Associated Press following a meeting in Baghdad with visiting US Defense Secretary Mark Esper, who arrived as Iraqi leaders chafed over reports the US may want to increase the number of troops based in Iraq, at least temporarily.

Iraq’s military said Tuesday that American troops leaving northeastern Syria don’t have permission to stay in Iraq in a statement that appeared to contradict Esper, who has said all US troops leaving Syria would continue to conduct operations against the Islamic State group from Iraq to prevent its resurgence in the region.

He later added that the troops would be there temporarily until they are able to go home, but no time period has been set.

Esper said earlier Wednesday that the US has no plans to leave those troops in Iraq “interminably” and that he plans to talk with Iraqi leaders about the matter.

Al-Shammari said Esper traveled to Iraq based on an invitation from the Iraqis. In Wednesday’s talks, he said the two sides agreed that the American troops crossing from Syria are “transiting” through Iraq and will then head to Kuwait, Qatar or the United States “within a time frame not exceeding four weeks.”

The Iraqi minister said the planes that would transport the American troops out of Iraq have already arrived.

Esper’s visit to Baghdad came a day after Russia and Turkey reached an agreement that would deploy their forces along nearly the entire northeastern border to fill the void left after President Trump’s abrupt withdrawal of US forces from the area, a move that essentially cleared the way for the Turkish invasion earlier this month.

It was unclear Wednesday what that means for US forces.

Trump ordered the bulk of the approximately 1,000 US troops in Syria to withdraw after Turkish President Recep Tayyip Erdogan stated in a phone call that his forces were about to invade Syria to push back Syrian Kurdish fighters, whom Ankara considers terrorists.

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

Esper said the troops going into Iraq would have two missions, one to help defend Iraq against a resurgence of Islamic State militants and another to monitor and perform a counter-IS mission.

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

The number of American forces in Iraq has remained small due to political sensitivities in the country, after years of what some Iraqis consider US occupation during the war that began in 2003. Iraqi leaders may privately condone more US forces to battle IS, but worry if it’s widely known that there will be backlash from citizens.

US troops in Syria fought for five years alongside Kurdish-led forces in northeast Syria and succeeded in bringing down the rule of IS militants — at the cost of thousands of Kurdish fighters’ lives. Under the new agreement, much of that territory would be handed over to US rivals.

The biggest winners are Turkey and Russia. Turkey would get sole control over areas of the Syrian border captured in its invasion, while Turkish, Russian and Syrian government forces would oversee the rest of the border region. America’s former US allies, the Kurdish fighters, are left hoping Moscow and Damascus will preserve some pieces of the Syrian Kurdish autonomy in the region.