WITH its rich reserves of oil and multitude of ethnicities and religions, the city of Kirkuk was always contested. The jihadist takeover of much of northern and western Iraq in 2014 allowed the Kurds both to take over the disputed city, and pose as defenders of Iraqi freedom. Now that Islamic State (IS) is being defeated, the old disputes over who controls the city have reignited.

In the early hours of October 16th, Iraqi government forces advanced on the city, taking over the oilfields, the biggest military base outside the city, and then the governorate building in the centre.

Oil production was briefly shut down. Thousands of civilians are fleeing the city and surrounding province, choking the Kurdish checkpoints on the roads into the mountainous north.

So far the casualties have been relatively light. Most Peshmerga fighters withdrew without much of a fight. But some Kurds in the city have responded to calls from their leaders to take up arms in Kirkuk’s defence.

Several factors are inflaming tensions. The first was a referendum on Kurdish independence last month. It had been called by the regional government’s president, Masoud Barzani, against the advice of many officials. Iraq’s prime minister, Haider al-Abadi, has vowed to prevent secession and halted international flights into Kurdish cities. Rival Kurdish factions are openly accusing each other of betraying Kirkuk.

Mr Abadi, sounding uncharacteristically belligerent, says the referendum will cost the Kurds “everything” they have gained since establishing an autonomous government in 1991. The loss of Kirkuk’s oilfields would certainly cost the Kurdish regional government its prime source of revenue at a time when it is already struggling to finance its rule.

Trade routes into the landlocked region have been severely impaired after Iran closed their common border. And Kurdish business interests elsewhere in Iraq have come under attack. Last week, gunmen attacked a regional office of Korek Telecom, a mobile-phone network run by Mr Barzani’s nephew, disabling its coverage in southern Iraq.

A second cause of conflict is the mounting tension between America and Iran. American diplomats are shuttling between Erbil and Baghdad, urging Messrs Abadi and Barzani, both of whom they consider allies, to restrain their forces. But America’s president, Donald Trump, risks undermining their efforts. On October 13th Mr Trump spoke out against Iran and vowed to curb its influence in the region.

He denounced the nuclear deal struck with Iran (and five other global powers) by his predecessor, Barack Obama, to lift certain sanctions on Iran in exchange for it curbing its nuclear programme and submitting it to tighter international scrutiny. Mr Trump also threatened to designate Iran’s Islamic Revolutionary Guards Corps (IRGC), the country’s praetorian guard, as a terrorist organisation.

The IRGC has responded to his bombast with force. Ahead of the Kirkuk offensive, General Qassem Suleimani, the head of the Quds Force, the IRGC’s foreign-operations arm, arrived in Iraq. Two armed groups closely linked to Iran—the Popular Mobilisation Units (or Hashd al-Shaabi) and the Federal Police—led the assault.

Across the border in Syria, Iran’s allies are also advancing, rubbing close to the Kurdish-led Syrian Democratic Forces, which are backed by America. On October 14th, Syrian forces took al-Mayadin, another town on the Euphrates, from Islamic State. Across the region, General Suleimani is demonstrating that while Mr Trump talks, Iran speedily acts.

Underlying these local fights is a broader scramble for vast swathes of the Fertile Crescent from which IS has retreated. Local militias and regional powers are racing to create facts on the ground. Raqqa, the capital of IS in Syria, is about to fall to American-backed Syrian rebels. But the Syrian government, and its Iranian and Shia allies, seem likely to win the race for control of Syria’s borders. Some still look for an agreed way forward. Last week Mr Abadi suggested establishing a joint administration in Kirkuk, involving Iraqi government and Kurdish officials. But as erstwhile allies in the struggle against IS turn their guns on each other, calls for negotiations look worryingly late.