ISTANBUL — Turkey on Monday withdrew some troops that had been sent to the outskirts of Mosul in northern Iraq to support a training mission, a deployment that had set off an angry reaction in Baghdad, where the authorities said they had never agreed to host Turkish forces.

Turkey has been training Kurdish pesh merga forces and Sunni Arab fighters — mostly policemen who fled Mosul’s capture last year by the Islamic State — in northern Iraq for nearly a year, but with the permission of only the local Kurdish government, not Baghdad.

When Turkey recently sent a new detachment of troops, with armored vehicles and tanks, to a camp in Bashiqa, near Mosul, it set off protests throughout Iraq. Demonstrators burned Turkish flags recently at gatherings in Baghdad and other cities, and Prime Minister Haider al-Abadi, saying the troops infringed on Iraqi sovereignty, vowed to seek action by the United Nations Security Council to force out the Turkish troops.

The episode has highlighted how divided Iraq is, and showed the weakness of the central government and its lack of control over its territory.