A seemingly chance meeting between a man accused of plotting to attack a passenger train and an undercover FBI agent who helped unravel the alleged plot in fact came about as part of an ongoing investigation, his terror trial heard Friday.

Testifying under cross-examination, the agent initially refused to confirm the meeting with Chiheb Esseghaier was no coincidence.

"I don't know if I can answer that. I don't think I can," the agent told defence lawyer John Norris.

However, he later conceded the meeting was a setup as part of an existing probe.

"You were tasked to form a relationship with him?" Norris asked.

"That's correct."

Court heard Esseghaier was involved in an altercation over seating at the Houston airport before a flight to California in June 2012 when the agent befriended him.

They ended up as seat mates for the almost four-hour flight and quickly hit it off, the agent .

The will to fight

In September 2012, the agent visited Esseghaier, a doctoral student in Montreal, and told him how their meeting had given his life a purpose, court heard.

"You had been inspired to more than just send money overseas: You wanted to be involved in some action," Norris summed up what the agent told his new friend.

"Sounds about right," the agent agreed.

"It had awakened in you the will to fight," Norris said.

Esseghaier began opening up about having visited Iran, court heard, where he had met "The Responsible One," a man with money and apparently close connections to terrorist mastermind Osama bin Laden.

He confided they wanted him to prepare a terror attack, court heard.

Esseghaier, who was "laser focused," the agent said, talked about having received training, including how to recruit people to carry out terror plots such as attacking the train, poisoning soldiers on a military base, or attacking non-religious Muslims.

It wasn't exactly good training if he ended up recruiting an undercover FBI agent, Norris said.

"I guess that would be viewed as a snafu," the agent responded.

Norris represents Esseghaier's co-accused, Raed Jaser, a dispatcher from Markham, Ont.

Esseghaier, who does not have a lawyer, earlier waived his right to cross-examine the agent, sitting motionless when the judge asked him if he had any questions of the witness.

'Obligation to jihad'

During the undercover agent's two weeks on the stand, court has heard extensive evidence about the alleged plot to attack the passenger train between New York and Toronto, much of it in hours of secret audio recordings.

"I am going to lose my mind in happiness," Esseghaier says of the developing relationship in one intercepted conversation with the agent.

Esseghaier also sought romance advice from the agent related to possibly marrying a young woman at work.

At another point, he said he wanted to see Islamic Sharia law imposed everywhere.

"I am making my obligation of jihad," he tells the agent. "I believe in it, but not just by words, but also by action."

The agent said he only spent about a total of about two weeks with Jaser, who withdrew from the alleged train plot, but spent hundreds if not thousands of hours with Esseghaier.

Esseghaier and Jaser were arrested in April 2013.