Patrick Shanahan is on a surprise visit to Baghdad for talks on future of troops following the withdrawal from Syria.

Patrick Shanahan, the acting US defence secretary, has arrived in Baghdad on an unannounced visit for talks on the continued United States troops presence in Iraq

“We are in Iraq at the invitation of the government and our interests are to build Iraqi security capability,” Shanahan told reporters travelling with him on his first trip to Iraq on Tuesday.

“I want to hear first-hand from them about concerns, the political dynamics that they are facing and then based on that we will obviously factor that into our planning.”

The acting Pentagon chief is due to meet Prime Minister Adel Abdul Mahdi and will also discuss the withdrawal of US troops from Syria with US commanders.

US President Donald Trump caused anger in Baghdad this month when he said he wanted to keep troops at the Ayn al-Asad airbase, northwest of Baghdad, to keep an eye on Iran “because Iran is a real problem”.

That move would overstep the US-led coalition’s stated mission in Iraq and Syria of defeating the Islamic State of Iraq and the Levant (ISIL, also known as ISIS).

US mission in Iraq

Iraq is in a difficult position as tensions between its two biggest allies, the US and Iran, increase.

Trump’s comments prompted almost universal criticism from Iraq’s leaders, including Abdul Mahdi, and raised questions about the long-term presence of around 5,200 US troops in the country, 16 years after the US invasion that toppled Saddam Hussein.

Iran-aligned politicians in Iraq’s parliament used the uproar to reiterate their demand that the US mission in Iraq be restricted and the number of troops reduced.

A draft law that would set a timetable for a US troop withdrawal is now before the Iraqi parliament.

It is backed by both of Iraq’s most powerful political groupings, the nationalist alliance led by Shia Muslim leader Moqtada Sadr, and the pro-Iran movement of former anti-ISIL fighters.

At a rare joint news conference on Monday, the two groupings demanded, at the very least, a “new agreement” setting tight conditions on any future foreign troop presence.

Those calls are likely to intensify as Washington carries out the full troop withdrawal from Syria unveiled in a shock announcement by Trump in December.

The plan prompted the resignation of Shanahan’s predecessor, Jim Mattis.

But with US-backed Kurdish-led fighters poised to overrun ISIL’s last enclave in eastern Syria, perhaps as early as this week, the withdrawal, which other administration figures had managed to slow, is now likely to gather pace.

Asked whether US troops in Syria could be moved to Iraq, Shanahan said on Tuesday that he would be having conversations on these topics during his visit.

He was in Afghanistan on Monday, where he met with US troops and President Ashraf Ghani amid a US push for peace talks with the Taliban.

Trump has indicated he would like to get US troops out of Afghanistan after 18 years of war, but Shanahan said he has no orders for a troop withdrawal.