The Iraq war is not over; it never really ended. It just spilled into a new war, the war in Syria. We may one day speak of Iraq-Syria the way that we speak now of 'Af-Pak'.

In response to a wave of attacks by the al-Qaida group known as the Islamic State in Iraq and Syria (ISIS), the United States is supplying Nuri Kamal al-Maliki's embattled government with Hellfire missiles and drones. The Obama administration also wants congressional approval to lease (and eventually sell) six Apache helicopter gunships to the Iraqis, a plan held up by lawmakers who fear they will be used against Maliki's political opponents.

As reported by the New York Times, the arming of the Iraqi government is a story about instability inside Iraq, counter-terrorism and the effectiveness of drones. But the regional implications are much larger. Maliki is after all not the only leader targeted by ISIS. It is an increasingly potent force in the Syrian insurgency, and has done much to tarnish its credentials as a liberation movement. ISIS wants to overthrow Bashar al-Assad's government as a first step in the creation of an Islamic caliphate.

During the American occupation of Iraq, the jihadists who later assembled under the banner of ISIS crossed into Iraq with help from Assad, who wanted to tie down American forces. Never fond of Assad (an ally of Shia Iran and an Alawi 'heretic'), they turned against him as soon as the insurrection in Syria broke out.

Assad's past sponsorship of Sunni extremists in Iraq is no doubt one reason Maliki loathes him. The Iraqi prime minister is said to have been reluctanct at first to back the Syrian government's counter-insurgency. But he came under pressure from Iran. And as groups like ISIS and the al-Nusra Front, another al-Qaida affiliate, gained the upper hand in the Syrian rebellion – and sent suicide bombers into Iraq at a rate of 30 to 40 per month – Maliki's choice was made for him.

In effect, the American government is arming a Shia-dominated state aligned with Iran and Assad, in order to fight Sunni extremists who want to bring down not only Maliki but Assad, too, an aim they share with Western-supported Syrian rebels. Or to put it differently: the American government is fighting Sunni extremists in Iraq, while its allies, notably Qatar and Saudi Arabia, are arming the same Sunni extremists in Syria.

Incoherent? Yes. But the question is whether this incoherence reflects the contradictory goals of stabilising Iraq and weakening Assad, or indicates a shift in American policy. The doctrine of counter-terrorism was the pillar of American policy in the Middle East from 11 September 2001 until the Arab revolts of 2011. It is now making a comeback in Washington, thanks to the resurgence of al-Qaida, militia rule in post-Gaddafi Libya and the fall of the Morsi government in Egypt.

The major losers have been the moderate Sunni Islamists who, only two years ago, seemed poised to run the region. Recep Tayyip Erdogan, who once seemed a neo-Ottoman sultan in the making, is mired in a corruption scandal; even the Islamists in Tunisia, the most competent and cautious in the region, have agreed to the formation of a technocratic government. General al-Sisi in Egypt has declared the Muslim Brotherhood a terrorist group and launched a brutal campaign against members and their assets, provoking hardly a murmur of criticism from the Obama administration. The US even withdrew the appointment of Robert Ford as ambassador to Cairo after the Egyptian government waged a Twitter war against him. Ford, the former ambassador to Syria and a seasoned Arabist, made no secret of his sympathy for the uprising in Syria, or of his belief that Sunni Islamists had to be included in the political process. That belief alone can land you in prison in Cairo as a 'terrorist'. Morsi all but assured his removal from power by the army when he appeared at an event where a group of radical imams called for jihad in Syria.

When Morsi was in power, secular liberals in the Arab world claimed that the US had entered into an alliance with Sunni Islamism, on the basis of a shared belief in free markets – and, it was often suggested, out of disdain for Arab democracy. But this 'alliance' with the Muslim Brothers was hardly more than a temporary marriage: America was merely testing the waters. Once an emboldened military imposed itself in Cairo (with the support of many liberals who set aside their professed commitment to civilian rule), and the Muslim Brothers were driven into jail or into hiding, the Obama administration swiftly accommodated itself to the realities on the ground. A similar reappraisal now seems to be underway in Washington with respect to Syria, where the moderate Islamist opponents of Assad are either too weak, too fragmented and too corrupt to wage an effective insurgency, or too close to jihadists that Western intelligence agencies consider an imminent security threat.

Assad, who has been keen from the outbreak of the rebellion to depict himself as fighting a battle against 'terrorism', is reaping the benefits. Ryan Crocker, a former US ambassador to Syria, recently argued in the New York Times that 'it is time to consider a future for Syria without Assad's ouster... As bad as he is, there is something worse,' namely a victory for ISIS and the al-Nusra Front. The struggle against such groups is also an interest that the US has in common with Assad's biggest foreign supporters: Russia and, more important, Iran, with which a cautious and potentially historic process of détente has begun over the enrichment of uranium. It would be a bitter irony if the graveyard that Assad has made in Syria became the flowerbed of rapprochement between Iran and the West.

It's not clear, however, that Iran will insist on the preservation of Assad himself. The Syrian war has allowed the Iranians – and their major proxy, Lebanese Hizbullah – to flex their muscles, but some Iranian leaders consider it a drain, and Assad is apparently not well liked in Tehran. At a recent conference in Doha, I heard rumours that Iran had asked Hamas to reach out to its friends in the Syrian insurgency. The message from Tehran: we are willing to drop Assad, so long as our interests are preserved in Syria. (Iran's principal interest in Syria is to insure that Damascus does not fall into the hands of Saudi Arabia, and that it remains a conduit of arms from Iran to Hizbullah.) Hamas would have agreed to deliver the message in order to get back into the good graces of a longtime patron – Iran is still angry at Hamas's decision to abandon Assad – without betraying the Syrian opposition. It's just a rumour, but it's revealing, all the same, of a growing perception that the road to peace in Syria runs through Tehran.

And not just in Syria: stability in Iraq and Afghanistan, and a settlement in Israel-Palestine, depend on Iran's co-operation. A window of opportunity has been created by the election of Hassan Rouhani, who – with his shrewd foreign minister Mohammed Javad Zarif and the blessings of the Supreme Leader Ayatollah Ali Khamenei – seems determined to establish détente with the West, so long as the Islamic Republic's place in the Middle Eastern state system, and its rights within it, are fully recognised. But this window won't be open for long, and America's traditional allies in Riyadh and in Tel Aviv, along with hardliners in the Iranian Revolutionary Guard, will surely do their best to shut it.