The alliance between Iran and Syria might seem an unlikely one. As Iran is an Islamic republic, one might not expect its closest ally to be a dictatorship that grew out of the political doctrine of Baathism, a secular Arab nationalist movement that originated in the 1930s and 1940s. But politics – and perhaps especially the politics of relations between states – develops its own logic, which often has little to do with ideology. Baathism advocated Arab unity but two of its founding fathers, Michel Aflaq and Zaki al-Arsuzi, both Syrians, disliked each other and would not be members of the same party.

Projects to fuse Syria and Egypt and, later, Syria and Iraq foundered, creating in the latter case a personal bitterness between Bashar al-Assad’s father, Hafez, and Saddam Hussein, though both were Baathists, at least nominally. That led to the two states breaking off diplomatic relations with each other at the end of 1979. When Iraq invaded Iran the following year, Syria and Iran became allies against Iraq. Syria cut off an oil pipeline that had allowed Iraq to export its oil from a Mediterranean port and Iran supplied Syria with cheap oil.

Iran and Syria had other things in common, including resistance to the US in the region, opposition to Israel and a supportive relationship with the Shia Muslims of Lebanon, which led to the creation, with Iranian help, of Hezbollah after the Israeli invasion of Lebanon in 1982. Since then, Syria has been of value to Iran as a reliable ally but also as a bridge to Hezbollah.

How does all that affect the present desperate situation in Syria and in the Middle East more widely? The first point to deal with is Iran’s position towards Islamic State, or Isis. Some commentators would have you believe that Iran and Isis, as so-called Muslim fundamentalists or Islamists, have something in common, or that Iran’s Islamic Revolution had something to do with the origins of Islamic State.

That is wholly misleading. The extreme Wahhabi/Salafi form of Sunni Islam that underpins Islamic State regards Shia Iranians – and, indeed, all Shia Muslims – as heretics and apostates. This hostility is not somehow theoretical or theologically abstract: it is visceral, bitter and deep. It inspires frequent suicide bombings of Shia mosques and other targets in Iraq, Pakistan, Afghanistan and (more recently) Saudi Arabia. It is a major threat to Iran and to all Shia Muslims – a greater threat to them than the Isis threat to us, because they are geographically closer. The Iranians are supporting the fight against Isis in Syria and Iraq in self-defence and supporting the self-defence of those they are sympathetic to in those countries (the Iranians back the Alawite Assads in Syria because of their long-standing alliance but also for sectarian reasons). They are not acting, as the Saudis and some other Gulf Arabs would have us believe, because they have hegemonic ambitions in the region. That view arises from the insecurity and paranoia of the ruling elites in those states and their dislike of Shia Muslims.

The Iranian regime has many faults. We may deplore the repressive policies of the regime internally, its treatment of women and the unacceptably high level of executions there. But on most of those points, there are others in the region that are worse; and in our thinking about what to do in Syria, Iraq and the region more widely, we have to consider Iran’s record as a force for stability or instability. In both Iraq and Afghanistan, the Iranians helped to establish the proto-democratic governments we backed and, like us, have consistently supported them since, despite their weaknesses and failings. With the exception of its policy towards Israel, Iran has acted to favour stability elsewhere in the region, too. (Recent reports suggest that the Iranians have stopped funding Hamas.) Considering the actions of the Saudis towards Shias in Bahrain and Yemen, the Iranians have responded with restraint.

Iran’s acceptance of greater Russian involvement in Syria has to be seen in the context of the wider instability in the Middle East. Again, we should not misjudge it. It seems that the latest, more intensive Russian intervention came at a point when the Assad regime was coming close to collapse. The Iranians were therefore bound to welcome the intervention; but the history of relations between Iran and Russia is not a happy one and a greater Russian military presence in the Iranians’ near abroad must be making some of them uneasy. When Russian ships launched cruise missiles from the Caspian Sea that tracked across Iranian territory on their way to targets in Syria (announcing at the time that this territory was “unoccupied”), “uneasy” was probably an inadequate word.

After the settlement of the Iranian nuclear question in July (when Iran agreed to limit its nuclear programme in return for the lifting of economic sanctions), hopes for further immediate co-operation between Iran and the West have been disappointed – in particular by the apparent ban of the supreme leader, Ali Khamenei, on bilateral discussions with the US. Nonetheless, there have been discussions, notably in the margins of the recent multilateral talks on Syria.

Just as there was opposition to the nuclear deal within the US, there was strong opposition in Iran. Khamenei’s ban is best understood as reassurance to those hardliners that, apart from the nuclear deal, it will be business as usual.

The nuclear deal is a major event in Iran’s foreign policy but if the Iranians are cautious in developing their relationship with the West, that may be no bad thing. The multi­lateral talks on Syria could be a good place for that to begin – those talks are, in any case, the best hope available for a solution to the carnage in that country. There are models for that in what was done recently in Somalia; one fruitful avenue to explore for the Middle East as a whole could be a multi­lateral negotiation culminating in a treaty guaranteed by outside powers, along the lines of the Westphalia Treaty that brought the Thirty Years War to an end in Germany in the mid-17th century.

Lurking in the background to all this, however, and behind the shocking massacres in Paris on 13 November, is our queasy position towards Isis and the troubles of the Middle East. Some Iranians believe that western countries secretly support Isis. That is wrong, of course – it is a view based on conspiracy theories and misleading propaganda – but not as wrong as we might like to think.

Since 1979, when the Saudi royal family got a scare from religious radicals briefly occupying the sacred precincts in Mecca, it has appeased extreme Wahhabi clergy within Saudi Arabia and has supported the application of their doctrines within and without the country. Outside Saudi Arabia, it has funded mosques preaching Wahhabism throughout the Islamic world, to the point that their brand of Sunni Islam is now becoming dominant in many communities where previously it was quite alien, symbolised by the practice of those British Pakistanis who have begun to adopt dress codes from the Arabian Peninsula, such as the wearing of the niqab.

Al-Qaeda, Isis and their sympathisers are the result of those 30 years of preaching hatred (along with other contributory factors such as the collapse into civil war in countries such as Iraq and Syria and the alienation of young men of immigrant origin in western countries). Isis does no more than put into practice the doctrines of puritanical intolerance advocated by Saudi Wahhabism. Our too-uncritical support for Saudi Arabia puts us in a shameful position.

The debate over whether or not to send RAF warplanes to bomb Isis positions in Syria is secondary to the need for the bombing to be done in close, effective support of ground forces. We may have to swallow our misgivings and accept that we bomb in support of Iran’s troops, or Assad’s, in addition to those of the Kurds or others.

We also urgently need to re-examine our relations with the Saudis and the other Gulf Arab States that have supported and encouraged the spread of extreme Wahhabism. The Saudis have belatedly realised that Isis is as much a threat to them as to everyone else (it may actually be more of a threat to Saudi Arabia because the jihadis’ dearest wish is to establish their caliphate in Mecca and Medina).

Yet that is not enough. We need to make clear that our continued friendship towards the Saudis cannot simply be bought with the weapons we sell them but has to be conditional upon taking a more responsible attitude in their religious policies – not so much for human rights reasons, as Jeremy Corbyn and others have suggested (although those reasons have their place) but for our security and for the stability of the Middle East region.

If that preaching of hatred is not stopped – as the preaching of the Catholic Counter-Reformation eventually came to an end – then even if we, the Iranians, Russians and others succeed in defeating Isis, we will only find ourselves confronted in a few years by yet another generation of murderous jihadis, recruiting from another bunch of foolish, ignorant and disaffected young men, just as Isis followed on from al-Qaeda.

Michael Axworthy is senior lecturer at the Institute of Arab and Islamic Studies at the University of Exeter and the author of “Revolutionary Iran”