When Al Qaeda leader Ayman al-Zawahiri spoke in an audio message broadcast to supporters earlier this month, he had harsh words for Iran. Its true face, he said, had been unmasked by its support for Syrian President Bashar al-Assad against fighters loyal to Al Qaeda.
Yet it is symptomatic of the peculiar relationship between Tehran and Al Qaeda that in the same month Canadian police would accuse "Al Qaeda elements in Iran" of backing a plot to derail a passenger train.
Shia Muslim Iran and strict Sunni militant group Al Qaeda are natural enemies on either side of the Muslim world's great sectarian divide.
Yet intelligence veterans say that Iran, in pursuing its own ends, has in the past taken advantage of Al Qaeda fighters' need to shelter or pass through its territory. It is a murky relationship that has been fluid and, say some in the intelligence community, has deteriorated in recent years.
"I wouldn't even call it a marriage of convenience. It's an association of convenience," said Richard Barrett, former head of counter-terrorism for Britain's MI6 Secret Intelligence Service and later head of the UN Security Council's monitoring team maintaining the world body's Al Qaeda and Taliban sanctions blacklists.
"It's not a strategic alliance. An Al Qaeda presence may suit the Iranians because it allows them to keep an eye on them, it gives them leverage in the form of people who are akin to hostages," he added.
"There has been a lot of travel between Iraq and Pakistan and I cannot imagine the Iranians are not aware of that," he said. But it was unlikely that Iran would take the risk of actively collaborating with Al Qaeda against North America: "I don't think the Iranians would take it kindly if it turned out that there had been plotting by Al Qaeda on their territory."
Canadian police have said there was no sign the plot had been sponsored by the Iranian state. Iranian Foreign Ministry spokesman Ramin Mehmanparast said Al Qaeda's beliefs were in no way consistent with Tehran's.
As yet, many details of the alleged plot remain unclear. However, a US government source cited a network of Al Qaeda fixers based in the Iranian city of Zahedan, close to the borders of both Pakistan and Afghanistan.
The source said they served as go-betweens, travel agents and financial intermediaries for Al Qaeda operatives and cells operating in Pakistan and moving through the area.
Another Western source suggested that with relations deteriorating between Iran and Al Qaeda over the civil war in Syria, Tehran had acted recently to stop fighters crossing through from Pakistan's Federally Administered Tribal Areas (Fata) to join Islamist militants fighting to overthrow Assad.
"Although the relationship between Iran and Al Qaeda has always been strained, this worsened after 2011 when the two sides lined up on opposite sides in the Syrian civil war," said Shashank Joshi, a researcher at the Royal United Services Institute think-tank in London.
"Syria's strongest rebel group is allied to Al Qaeda, and both have sharply criticised Iranian support for the Assad regime."
It is unclear whether the planning for the alleged Canadian plot, which Canadian police said had been in the works for some time, was carried out before Syria's war deepened the strain between Tehran and Al Qaeda.
"There has been a loosening of the ties," said Barrett, noting that documents released after US forces caught and killed Osama bin Laden in Pakistan in 2011 showed the Al Qaeda leader saying he was not able to trust the Iranians at all.
"Since then we have Zawahri castigating Iran quite recently. So clearly something had gone wrong."
Iranian control far from clear
If indeed the Al Qaeda network was based in and around Zahedan — which lies on the main road to Pakistan and is the capital of Sistan-Baluchestan province — it is far from clear how easy it would be for Iran to control.
The region is home to a toxic mix of drug smuggling, illicit trade and gun-running by insurgents. Afghan refugees long ago crowded into poor neighborhoods on the outskirts of Zahedan, although Iran, like Pakistan, periodically tries to push them out, arguing they are a security risk.
Iranian authorities have also been battling a Sunni insurgency of their own in recent years by ethnic Baloch complaining of discrimination. The Jundollah group has claimed several attacks including a bombing that killed 42 people in 2009 — there is no sign it is linked to Al Qaeda, though it is often confused with a Pakistan-based group of the same name.
At the same time, on the Pakistan side of the border, Pakistani security forces are fighting an insurgency by secular Baloch separatists, while Al-Qaeda linked militants in the Sunni sectarian Lashkar-i-Jhangvi group have carried out a string of attacks against the Shia population there.
Despite a common Western misconception that Iran, as the pre-eminent Shia power, is motivated by religion, it has always been much more pragmatic in pursuing its national interest, analysts and diplomats say, allowing it to turn a blind eye to Sunni Al Qaeda using its territory.
"The thing that has stymied people is that ‘Al Qaeda is Sunni and the rest of the people we are talking about here are Shia. They don't mix and match.' Well, they do. And they do it whenever they want to. They just look the other way," said Nick Pratt, a retired US Marines colonel and CIA officer now with the George C. Marshall European Center for Security Studies.
Before the US-led invasion of Afghanistan in 2001, Iran cooperated with India and Russia against the Pakistan-backed Taliban then in power in Kabul. When Al Qaeda members fled Afghanistan after the overthrow of the Taliban, it detained them under house arrest in Tehran.
"Since 9/11 a number of senior Al Qaeda figures including one of Osama bin Laden's sons and senior commander and strategist Saif al Adel made their way to Iran," said Nigel Inkster, former director of operations for Britain's MI6.
"They were detained under quite strict conditions by the Iranian authorities who subsequently sought to use them as a bargaining chip with the US government in their ongoing dispute about Iran's nuclear program," added Inkster, who is now director of Transnational Threats and Political Risk at the International Institute for Strategic Studies.
Vahid Brown, a US-based researcher who has written extensively on Al Qaeda, said in an article on the Jihadica website earlier this year that the men who fled to Iran constituted a dissident faction within Al Qaeda, which in recent years had become increasingly vocal in their criticism of Osama and Zawahiri.
Divided by their views on the advisability of the September 11, 2001 attacks on the United States, broadly speaking, "the pro-9/11 group, including bin Laden and Zawahiri, fled to Pakistan, while the anti-9/11 group ended up in Iran, where they were placed under house arrest by Iranian authorities," he wrote.
Iran had been willing to cooperate with the United States on Afghanistan initially, but relations soured after Tehran was denounced by then President George W. Bush as part of the "axis of evil" in 2002 and worsened further after the US-led invasion of Iraq in 2003.
Later, analysts say, Tehran allowed Al Qaeda members — among them Al Qaeda in Iraq leader Abu Musab al-Zarqawi — to transit through Iran.
But Iran has been vulnerable to Al Qaeda as well. After one of its diplomats was kidnapped in Pakistan some years ago it released some of the Al Qaeda members it had under house arrest in exchange for his freedom, according to Pakistani media reports.
"About 18 months ago the Iranians released most if not all of those they were holding, for reasons still not entirely clear," said Inkster.
"There may well be a residual AQ presence in Iran though I would be cautious about presenting it as something very structured or hierarchic," he added.
"AQ is far from being the organisation it once was and what matters more are relationships between like-minded individuals. And that may well be what we are seeing in the Canada case. There seems to be no evidence of Iranian official involvement."