The Iraqi government has recaptured a swathe of northern Iraq from the Kurds in a sudden campaign that has shifted the balance of power in the country almost overnight. Kurdish forces lost more territory on Tuesday (17 October), withdrawing from the town of Sinjar a day after Iraqi forces pushed them out of the disputed city of Kirkuk. Kurdish troops also pulled out of the long disputed Khanaqin area near the Iranian border.

Iraq's dramatic move against the Kurds came almost immediately after they had fought side by side to rid the country of Islamic State (Isis/Daesh).

Kirkuk Iraq Kurds
Iraqi forces flash the sign for victory while driving towards the city of Kirkuk Ahmad al-Rubaye/AFP

The government advances have redrawn the map of northern Iraq, taking back territory that the Kurds had captured. Most of the advances appear to have come unopposed, with Kurds withdrawing before government forces moved in.

The Kurds officially govern three northern provinces of Iraq in an autonomous region, but they have also occupied a wide crescent of additional territory in northern Iraq, much of which they captured after helping drive out Isis.

Kirkuk has found itself at the heart of a long-running dispute between Iraq's autonomous Kurdish region and its central government. When Iraq's armed forces fell apart in the face of an advance by Isis in 2014, Kurdish forces moved into Kirkuk to secure the city and its surrounding oil wells.

Baghdad has since insisted Kirkuk and its province be returned to the central government, and matters came to a head when the Kurdish authorities included Kirkuk in their independence referendum, even though it is 32 kilometres (20 miles) outside the autonomous Kurdish region. To the Iraqi central government, that looked like Kurdish expansionism.

Prime Minister Haidar Abadi ordered his troops to raise their flag over all Kurdish-held territory outside the autonomous region itself. They achieved a swift victory in Kirkuk, reaching the centre of the city in less than a day.

Just three months ago the Kurds, Iraqi troops, and the Shia militia were fighting together to recapture Mosul from Isis. Two weeks ago they expelled the jihadists from Hawija, their last bastion in northern Iraq.

When Isis seized Sinjar in 2014, they massacred the Yazidis, killing more than 2,000 men. Kurdish forces, supported by US airstrikes, liberated the town in 2015, freeing thousands of Yazidi women and children who had been held as slaves. On Tuesday (17 October), Kurdish forces withdrew before dawn, allowing Iraqi Shia militiamen to move in.

For the Kurds, the loss of territory, particularly Kirkuk which Kurdish folklore views as the heart of their homeland, is a severe blow just three weeks after they voted to declare their decades-old objective of an independent state. The Kurds are the fourth-largest ethnic group in the region and they are spread across Iran, Turkey, Syria and Iraq, all of which oppose any moves towards a Kurdish state.

Turkey, which had developed a good working relationship with the Iraqi Kurds and let the landlocked region export oil through its pipes, has swung behind Baghdad, furious at a secession move that might ignite similar demands from its own Kurds. Turkey said it will close its air space to KRG territory and hand control of the main border crossing into the region to the Iraqi government.

Kirkuk, a city of more than one million, is home to Arabs, Kurds and Turkmen, as well as Christians and Sunni and Shia Muslims.Thousands of civilians have begun streaming back with their children and belongings packed tightly in their cars. Members of the Turkmen ethnic group who have opposed Kurdish rule, have driven through the streets in convoys, firing weapons in the air. Many Kurdish residents, fearful of federal and Shia militia rule, have packed up and gone north to Irbil, the capital of the northern autonomous Kurdish region.

With the common enemy now defeated, the danger is that Iraq's divisions will widen – and the long-simmering sectarian violence between Kurds, Sunnis and Shias will once again erupt.