Fear of the Islamic State of Iraq and the Levant (Isis, who now refer to themselves the Islamic State ) is the new uniting factor for states in the Middle East and beyond who normally hate each other. The sudden emergence of Isis's still expanding caliphate, with its terrifying blend of brutality, bigotry and military effectiveness, provides a common enemy for the US, Iran, EU states, Saudi Arabia, Turkey and, in Iraq, Shia, Kurds and anti-Isis Sunni.
It was the capture of Mosul by Isis on 10 June which ended the eight-year rule of Nouri al-Maliki, who withdrew his candidacy for a third term as prime minister last Thursday. A diversity of Iraqi politicians and parties, intermittently supported by foreign powers, have been trying to get rid of him for years, but they failed because of their disunity and his control of the Iraqi state. It was Isis gunmen in their captured Humvees patrolling the roads an hour's drive from Baghdad that created the determination to finally get rid of Mr Maliki.
However deep the differences between Washington and Tehran, they were equally horrified by the prospect of Isis advancing on Baghdad and Erbil. Saudi Arabia has openly or covertly opposed Iran and Shia Islam since the overthrow of the Shah in 1979, but is seriously threatened by Isis, whose ideology is not much different from Saudi Wahhabism but challenges the legitimacy of the house of Saud. Last Friday in Mecca, the influential imam and preacher at the Grand Mosque, Sheikh Abdul-Rahman al-Sudais, called for a code of conduct to stop leaders, scholars and young people supporting violence and "terror". An implication of this is that Saudi Arabia will suppress pro-jihadi propaganda on the internet and satellite television which it has previously encouraged.
The Iranians are also facing a more menacing future as Isis fighters tighten their grip on Diyala province in Iraq, which is on the Iranian border. A year ago a senior member of the Islamic Revolutionary Guard Corps explained how necessary it was for Iranian security to fight in Damascus although it is 870 miles from Tehran; but last week Isis, which considers Shia to be heretics worthy of death,  captured the town of Jalawla, 25 miles from Iran. No wonder Iran was willing to say goodbye to Mr Maliki, whom it had so long defended, to end the political crisis in Baghdad.
The realisation of the danger posed by Isis did not come immediately with the fall of Mosul and Tikrit. In Baghdad, and abroad, there was wishful thinking that Isis was the fanatical shock-troop of an insurgent Sunni community in Iraq; and that once Mr Maliki was gone and reforms acceptable to the Sunni were implemented, then traditional tribal and non-Isis military leaders would reassert themselves and get rid of the dangerous zealots.
It was always a dubious argument, with much evidence to the contrary. Isis, after its experience in 2006 and 2007 when the Americans did succeed in splitting the Sunni insurgency, is wary of another stab in the back. It has taken precautions such as demanding a pledge of allegiance to the caliphate and, according to one account from Mosul, has seized 300 former Baathists and army officers as hostages. The lesson from Iraq and Syria is that in places it has conquered, Isis only shares power as long as it has to. So far, the chances of a counter-insurgency against it in Sunni provinces look bleak.
But this does not mean that Isis has not created a host of enemies for itself, and it is losing the advantage of its opponents' disunity. Within Iraq, relations between Erbil, the Kurdish capital, and Baghdad were "poisonous", the Iraqi foreign minister, Hoshyar Zebari, told me in early July. But the victorious Isis attack on Kurdish-held territory in August has made the Kurds less over-confident and more willing to cooperate with the Iraqi central government against the jihadis. Among the Kurds themselves there was a closing of the ranks as experienced fighters of the Kurdistan Workers Party (PKK) raced to help the Iraqi Kurdish forces with whom they had previously had hostile or very frosty relations.
With both the Shia and the Kurds feeling vulnerable, the US has restored much of its former influence in Iraq with a few air strikes.  In contrast with American ignorance and arrogance in 2003, Washington is now much more knowledgeable and warier of the Iraqi quagmire. As states such as Saudi Arabia, Turkey and Iran find ferocious and battle-hardened Isis fighters on their borders, they are more likely to cooperate with each other and the US. In the words of Hillaire Belloc's poem, they're keeping "a-hold of Nurse, For fear of finding something worse."
This coming together of old rivals and enemies in opposition to Isis is happening in Iraq, but not yet in Syria where the US, Europeans, Turks, Saudis and Qataris continue with their old bankrupt policy. This is to get rid of or least weaken President Bashar al-Assad by backing a moderate military opposition that is supposedly going to fight both Mr Assad and Isis. Unfortunately, this group scarcely exists except as a propaganda slogan and a consumer of subsidies from the Gulf. Isis dominates the Syrian opposition and that domination grew greater last week as it captured the towns of Turkmen Bareh and Akhtarin, 30 miles from Aleppo.
The Sunni rebellion in Syria may soon be an Isis controlled project as it already is in Iraq. Given that Syria is 60 per cent Sunni Arab, compared to 20 per cent in Iraq, it is easier for Isis to increase its strength there. Any attempt to counter-attack Isis that focuses solely on Iraq is likely to fail because the caliphate straddles the two countries' border.
The present US policy of leaving Mr Assad (backed by Hezbollah, Iran and Russia) to battle Isis alone poses high risks, says Anthony Cordesman, the national security analyst at the Center for Strategic and International Studies in Washington. He writes that US policy only works so long as the Assad forces do not lose territory and key cities to Isis and the caliphate "does not make major economic, military, political and religious gains". He adds that the present stance of the US and its Arab allies assumes the existence of a moderate Sunni resistance not dominated by Isis. If Isis is able to maintain its "sanctuary" in eastern Syria, the caliphate will be able to reinforce its "capabilities in Iraq and steadily increase the threat to Lebanon, Jordan, Saudi Arabia, Turkey and other neighbouring states".
In practice, none of the conditions for a successful US policy in Syria have been met. Since Isis expanded its caliphate to cover almost all of eastern Syria, its neighbours have every reason to be frightened. The nascent unity and cooperation of the opponents to Isis forged by the Iraq crisis may be too little and too late.
By Patrick Cockburn