TORONTO—Canadian police said they foiled a plan to attack a passenger train in Toronto that they said was supported by al Qaeda operatives in Iran, and charged two men with conspiracy to carry out the alleged attack.

Investigators believe the train to be targeted was either bound for or leaving from New York, said a person familiar with the investigation.

The...