Canadian authorities claim al-Qaeda operatives in Iran directed a failed plot to attack a passenger train.

Iran denies it has any links to the two suspects: Raed Jaser, 35, of Toronto, and Chiheb Esseghaier, 30, of Montreal.

What falls in between is Iran's complicated history with the extremist group that has included outright hostility, alliances of convenience and even overtures by Tehran to assist Washington after the Sept. 11, 2001, attacks.

Are Iran and al-Qaeda allies?

Relations have always been rocky. Iran has been at odds with al-Qaeda on many fronts. A fundamental divide is over the two main branches of Islam. Iran is mostly Shia. Al-Qaeda is nearly exclusively Sunni-led. Some hardline militants backing al-Qaeda consider Shia Muslims as heretics and view Tehran's regional ambitions as a greater threat than the West. Sunni insurgents in Iraq, for example, have used car bombs and suicide attacks against Shia targets, killing thousands since 2003. In January 2011, the al-Qaeda faction in Yemen declared "holy war" against Shia rebels that are believed to be supported from Tehran. Iran also has been incensed by al-Qaeda backing for Syrian rebels seeking to overthrow the regime of Bashar al-Assad, one of Tehran's main allies in the region.

Before the Sept. 11 attacks, Iran was even more outspoken than Western countries against the Taliban, which sheltered Osama bin Laden and other al-Qaeda leaders. In 1998, eight Iranian diplomats were killed when Taliban forces overran Mazar-i-Sharif in northern Afghanistan and were accused of the systematic slayings of Shias. The rights group Amnesty International said Taliban fighters stormed the Iranian consulate as part of its anti-Shia purges.

A June 2009 al-Qaeda memo — possibly to bin Laden — refers to the Iranian government as "criminals" and bashed its opaque and unpredictable policies. The document was among files seized in the May 2011 raid that killed bin Laden and was posted online last year by the U.S. Army's Combating Terrorism Center.

How did al-Qaeda figures end up in Iran?

After the U.S.-led attacks against the Taliban in late 2001, scores of al-Qaeda foot soldiers, leaders and some of bin Laden's relatives fled over the border into Iran. Iran put many under house arrest-style detention, but refused to send them to U.S. allies, such as Saudi Arabia, where they could face extradition or interrogations by American forces. Tehran's leadership believed that holding bin Laden relatives and al-Qaeda officials could offer a guarantee against anti-Shia attacks. It also was seen as an unexpected bargaining chip with the West for Tehran's leadership, which rejoiced in the Taliban's downfall but was fearful of U.S.-led forces next door.

Who were among the high-level al-Qaeda operatives in Iran?

Al-Qaeda's senior military strategist Saif al-Adel was in Iran for years with his family. He was under close surveillance, but apparently received more freedoms to travel abroad and have greater contacts as part of a deal in 2010 to free a kidnapped Iranian diplomat in Pakistan's tribal areas, where al-Qaeda still carries strong influence. It's unclear whether he remains in Iran or has shifted to other areas, possibly Pakistan. Several reports he was killed have not been verified in recent years, but speculation continues to be fuelled by a lack of confirmed sightings or statements. Al-Adel, an Egyptian, allegedly helped mastermind the 1998 bombings of U.S. embassies in Africa and is among the FBI's most-wanted militants.

Another top al-Qaeda official, bin Laden son-in-law Sulaiman Abu Ghaith, lived in Iran for about a decade, according to U.S. investigators. Abu Ghaith — a Kuwaiti stripped of his citizenship by the Western-allied Gulf nation — was captured by the FBI in Jordan in February and would be the highest-ranking al-Qaeda figure to stand trial on U.S. soil since the Sept. 11 attacks. He served as al-Qaeda spokesman and fundraiser before the group's leaders fled Afghanistan and possibly continued some work from Iran, security analysts say. Abu Ghaith also was given more freedoms to travel outside Iran in the deal to free the Iranian diplomat.

Could al-Qaeda operatives in Iran have a role in co-ordinating an attack in the West without Tehran's knowledge?

 In the past, Iran kept a very close eye on all al-Qaeda figures in the country. Iranian intelligence services had access to all communications and contacts. The apparent loosening of restrictions following the diplomat-release deal, however, raises new questions. They include whether al-Qaeda operatives in Iran could now make trips outside the country to places such as neighbouring Pakistan or Iraq to make connections with the wider network of extremist groups. Also, Iranian officials are increasingly focused on economic troubles from international sanctions over Tehran's nuclear program. Keeping watch over the al-Qaeda remnants in Iran may no longer have the same priority.

Did Iran help the West in efforts to identity al-Qaeda fugitives?

To some extent, yes. In 2003, Iran gave the UN Security Council the names of 225 al-Qaeda suspects detained after illegally crossing into Iran and deported to their countries in the Middle East, Europe and Africa. Earlier, Iran had rounded up hundreds of Arabs who had crossed the border from Afghanistan. Most were expelled, but not before Iran made copies of nearly 300 passports and other documents in an apparent effort to help the U.S.-led efforts to track the al-Qaeda networks after the Sept. 11 attacks. Iran's offers of co-operation with Washington came to a halt after being named in 2002 as part of President George W. Bush's "axis of evil."