When the guns fell silent on the Kirkuk-Erbil road, just after noon on Friday, a fresh border had been scythed through the oil-rich soil – and a new line of influence carved across northern Iraq.

Their gun barrels still hot, vanquished peshmerga forces began another withdrawal a few miles closer to the seat of government in the now shrunken boundaries of Iraqi Kurdistan. A few miles south, closer to Kirkuk, Iraqi forces were digging in, their conquest of the entire province complete, and their five-day sweep through the rest of the north having seized up to 14,000 sq km from the Kurds, with a minimum of bother.

Baghdad has now reasserted its authority over territory that the Kurds occupied outside their mandated borders, most of which they had claimed during the three-year fight against the Islamic State (Isis) terrorist group.

The extraordinary capitulation – which followed an indepedence referendum that was supposed to strengthen their hand – has not only shattered Kurdish ambitions for at least a generation; it has also laid bare an evolving power struggle in Iraq, and a regional dynamic that is fast taking shape in the wake of the shattered so-called caliphate declared by the Isis leader, Abu Bakr al-Baghdadi, in mid-2014.

Lining up to claim the rout of the Kurds were Iraq’s prime minister, Haider al-Abadi, and Iran’s omnipresent general, Qassem Suleimani, whose influence in the days before last weekend’s attack was key to shaping the aftermath even before a shot had been fired.

Iranian government officials, too, were celebrating the win in Kirkuk, which the Kurdish leader, Massoud Barzani, had in effect annexed by including it within the boundaries in which the referendum was held. “We were never going to let a Zionist project like this claim Kirkuk,” said a senior leader of the Shia-led forces, known as the Popular Mobilisation Units (PMUs). “Kirkuk is central to Iraq’s economy and it will never belong to Barzani.”

Contested throughout history, Kirkuk is home to Kurds, Arabs and Turkmen, as well as oilfields, an airport, a strategic military base – and at least 8,000 million barrels of subterranean oil. It has powered the oil-dependent Kurdish economy for the past three years, with up to 600,000 barrels a day exported through a pipeline it built to Turkey, much to Baghdad’s chagrin.

The fall of Kirkuk has also unearthed a faultline that lay at the heart of the decision to hold the referendum, which won 93% endorsement among those Kurds who turned up to vote, but was never wholeheartedly endorsed by the Talabani clan, whose peshmerga forces had been responsible for defending its southern approaches.

“They could never get past it being led by Barzani,” said an Iraq-based European diplomat. “Beyond that, it was always going to put them in an impossible situation with Iran, who would invade Iraq before losing it. And I think deep down they probably saw this as not something you could resolve through a unilateral declaration.”

In Baghdad, the Iranian claims of being central to the victory were repeatedly being disavowed. “The popular myth is that a certain Iranian general has a hand in everything in this country, that he is a viceroy of some sorts,” said a senior Iraqi minister. “That’s not true. This is a country that has been through a lot and is getting back on its feet through the blood of its martyrs and the sacrifice of its citizens.”

Asked why he declined to put his name to his remarks, the MP cited “the sensitivity of the situation”. He then added: “It isn’t wise to upset [Iranian officials].”

While Iraq’s military indeed played a prominent role in reclaiming Kirkuk, so, too, did Shia groups who report to Suleimani and the joint leaders of the PMU forces, Hadi al-Amiri and Abu Mahdi al-Muhandis. Days before the referendum, it was al-Amiri who sent an envoy to Barzani threatening “war” if the poll went ahead. Suleimani also sat opposite the de facto Kurdish president to try to dissuade him, according to a senior Kurdish officials. When that did not work, he requested – and was refused – a second meeting. And, over the past two months, he had been a regular visitor to the rival political camp in the Kurdish north – the Talabani family, in the region’s second city, Sulaymaniyah.

The US, which was vehemently opposed to the ballot – especially the decision to include Kirkuk – insisted that despite the latest Iraqi move the areas that the central government has “seized” remain disputed.

Washington sat out the past week of clashes, even as forces loyal to Suleimani helped lead the assault.

Facebook Twitter Pinterest Iraqi Kurds wave flags of Iraqi Kurdistan and shout slogans during a demonstration outside the UN Office in Erbil. Photograph: Safin Hamed/AFP/Getty Images

The spectre of an ascendant Iran has been central to the Trump administration’s rhetoric in the past week, as the US president ponders tearing up the Iran nuclear deal – the centrepiece of his predecessor’s detente with Tehran.

“You have to say that this defiance [by Iraq] was at odds with what clearly happened,” said a former US diplomat in Iraq. “Yes, the Iraqis did fight and no, they weren’t a distant second in influence. But the Iranian role here can’t be denied. And nor can the fact that this is a prime example of a bigger struggle for the Iraqi street. This is Najaf v Qom [Shia power bases in Iraq and Iran] writ large.”

“The political and military campaigns around Kirkuk were organised by Suleimani,” said an Iraqi minister. “Make no mistake about it. Anyone who thinks he defers to Abadi does not understand how business is done in Iraq.”

On Saturday, 15 October, with Iraqi and Shia forces massed near Kirkuk, the Kurdish factions – the KDP, which is led by the Barzanis, and the PUK, a fiefdom of the Talabanis – sat down to talk in the lakeside town of Dukan. Barzani arrived with his son Masrour, and other senior officials. On the PUK side, Hero Ibrahim Ahmed, the widow of the PUK father-figure Jalal Talabani, who had died just over a week earlier, led a delegation including her eldest son, Bafel, and security tsar Lahur.

“Bafel said he had met with Abadi and discussed allowing the golden division (Baghdad’s counter-terrorism forces) into Kirkuk. He said the Republican Guard might take control of some of the sites,” said a senior Kurdish official. “We asked him if he had made an agreement, and he said ‘no, they were just discussion points’. We said if he had agreed to that, we would have to adjust our force posture accordingly.

“They lied. It was a historical betrayal. The deal was done while condolences were received for Talabani, first in Sulaimaniya, and then in Baghdad. The second meeting is where Abadi was also informed.”

KDP officials also believe that Bafel and Lahur held two previous meetings with leaders of the PMUs – one of which Suleimani attended – in Tuz Khurmatu, 37 miles south of Kirkuk.

Speaking on Friday, Bafel Talabani described the decision to hold a referendum as “a colossal mistake. And even in the fighting in Kirkuk, there was an opportunity. Prime Minister Abadi, his excellency, reached out to us and we reached an honourable compromise,” he said of the move to withdraw peshmerga forces.

As the defeated peshmerga forces redrew their defences on Saturday, the new boundary north of Kirkuk – where a de facto line marked out areas disputed between Kurds and Arabs after the fall of Saddam Hussein – was busily being fortified by Iraqi forces, among them Shia groups.

“This has been the most painful lesson they have faced,” said a PMU member further along the road in Kirkuk.

“Let them reflect on that, and on history. Kirkuk will never be Kurdish.”