BRAMPTON, Ont. — A Toronto security guard’s alleged plan to fly to Egypt and make his way to Somalia to join the terrorist group Al-Shabab might have worked, a federal prosecutor told jurors on Monday.

“The problem is, he shared it with the wrong person,” Crown lawyer Iona Jaffe said in her closing arguments as the case — the first of its kind in Canada — wrapped up following more than two months of arguments and testimony.

The “wrong person” Mohamed Hersi allegedly confided in was an undercover Toronto police officer sent to befriend him after a guidebook on making homemade explosives was found on a USB memory stick he left in his uniform.

For five months, the officer met Mr. Hersi and, sometimes with the tape recorder rolling, they discussed the details of joining Al-Shabab. He faces two terrorism-related counts, including counselling the officer to join the terror group.

As the trial entered its final stages this week, the courtroom at the Ontario Superior Court of Justice was packed to overflowing with supporters of Mr. Hersi, many of them women wearing traditional Somali dress.

Jurors were to begin deliberating Wednesday on the fate of Mr. Hersi, a 28-year-old refugee from Mogadishu and University of Toronto graduate who was arrested at Toronto’s Pearson airport in 2011 as he was about to board a flight to London.

From there he was ticketed to Cairo but the Crown alleged that while he had told his mother he would be studying Arabic in the country, Egypt was simply a temporary stopover. “He was moving on to Somalia,” Ms. Jaffe said.

Using a slide show, she walked the jurors through comments Mr. Hersi had allegedly made to the undercover officer, indicating he was going to “the motherland to join our brothers in Al-Shabab” and that it was the “ultimate sacrifice you can make for your religion.”

‘It was anathema to him. He couldn’t join Al-Shabab’

She said he had a contact in Al-Shabab, a former Toronto high school friend named Abdurahman “Casanyo” Guled, and that shortly before he was to leave, Mr. Hersi had accepted a friend request from him on Facebook.

The Crown also argued Mr. Hersi had given encouragement to the undercover officer, who was pretending he was interested in joining Al-Shabab. “There’s constant advice and it was all packaged in an encouraging way.”

Mr. Hersi advised him about concocting an alibi, getting to Somalia, buying guns and urged him not to “burn any bridges” because Al-Shabab might want him to return to Canada to “take care” of those who insulted the Muslim prophet Muhammad, she said.

But defence lawyer Paul Slansky said Mr. Hersi was simply on his way to Cairo to study Arabic when he was arrested and would have never enlisted in the terror group because it was contrary to his beliefs and his mother would have disowned him.

“It was anathema to him,” Mr. Slansky told jurors in his closing arguments on Monday. He said Mr. Hersi considered his mother his best friend and joining would have damaged their relationship. “He couldn’t, he wouldn’t join Al-Shabab.”

Mr. Hersi considered the group “tyrannical” and believed that terrorism was against Islam, he said. Furthermore, his Somali clan was opposed to Al-Shabab. “I would suggest that he had a motive not to join Al-Shabab,” Mr. Slansky said.

While the undercover police officer testified that Mr. Hersi had admitted in January 2011 that he was planning to join, Mr. Slansky accused the officer of making that up to save an undercover investigation that was struggling to produce results.

Three months into the operation, police were having concerns about its speed and direction, and had identified investigative gaps. The RCMP Integrated National Security Enforcement Team had been approached about taking it over.

But just when the investigation was at this critical stage, the undercover officer reported that Mr. Hersi had admitted he was going to join Al-Shabab. The alleged confession occurred just before police began recording the conversations.

Mr. Slansky accused the officer of falsifying his notes to save a faltering investigation. “This was the time to fabricate a full confession,” the lawyer said, adding that Mr. Hersi “didn’t say what the undercover officer said he said. It’s a lie.”