Two men were arrested on Monday night and charged with plotting a terrorist attack against a Canadian passenger train with support from al-Qaida "elements" in Iran, Canadian police said.

Chiheb Esseghaier, 30, and Raed Jaser, 35, who live in Montreal and Toronto, were planning to derail a Via Rail passenger train in Toronto but posed no immediate threat, according to the Royal Canadian Mounted police.

"This is the first known al-Qaida-planned attack that we've experienced in Canada," said Superintendent Doug Best.

RCMP assistant commissioner James Malizia said the two men had direction and guidance from "al-Qaida elements located in Iran," though there was no reason to think the planned attacks were state-sponsored.

Police said the men did not get financial support from al-Qaida, but declined to provide more details.

"It was definitely in the planning stage but not imminent," RCMP chief superintendent Jennifer Strachan said. "We are alleging that these two individuals took steps and conducted activities to initiate a terrorist attack. They watched trains and railways."

Strachan said they were targeting a railway, but did not say if it was a cross border route.

A spokeswoman for the University of Sherbrooke in Montreal said Esseghaier studied there in 2008-09. More recently, he has been doing doctoral research at the Institut National de la Recherche Scientifique, a spokeswoman at the training university confirmed.

This is the first time Canadian police have laid charges related to an al-Qaida-supported attack on Canadian soil. Neither man is a Canadian citizen, but police would not comment on their nationality.

The two suspects, who are expected to appear in a Toronto court on Tuesday, were arrested in Toronto and Montreal as part of a major national security investigation called Project Smooth which was initiated in August 2012.

The attack was thwarted by a cross-border joint task force between Canadian police, the intelligence branch, the FBI and US department of homeland security.

Via Rail tweeted on Monday that thanks to unprecedented co-operation between law enforcement and security units of various departments "at no time was there an imminent threat to the public".

Law enforcement officials said the terror suspects had no connection to the Tsarnaev brothers, who are suspected of last week's Boston Marathon bombings, nor to the high school friends from London, Ontario who joined al-Qaida in the Maghreb and died in a bloody shootout in January after taking the In Amenas gas complex in Algeria hostage.

Al-Qaida's relationship with Iran's government is unclear but has occasionally been fractious in the past. However, Bruce Riedel, a CIA veteran who is now a Brookings Institution senior fellow, said al-Qaida has had a clandestine presence in Iran since at least 2001 and that neither the terror group nor Tehran speak openly about it.

"The Iranian regime kept some of these elements under house arrest," he said in an email to the Associated Press. "Some probably operate covertly. Al-Qaida members often transit Iran travelling between hideouts in Pakistan and Iraq."

Canada severed diplomatic relations with Iran, closed its Tehran embassy and expelled Iranian diplomats from Canada in September 2012 with Canada's foreign minister, John Baird, calling Iran "the most significant threat to global peace and security in the world today."

Security sources told the Canadian broadcaster CBC that the alleged plot was potentially more dangerous than the bombings and hostage-takings planned by the so-called Toronto 18 in 2006, a home-grown plot to set off bombs outside Toronto's stock exchange, a building housing Canada's spy agency and a military base. Their goal was to scare Canada into withdrawing troops from Afghanistan and the arrests made international headlines.