In the midst of a frenzied attack on soldiers at the Canadian Forces recruiting centre in north Toronto on Monday, the attacker declared he was driven to violence by a higher power.

"Allah told me to do this. Allah told me to come here and kill people," the attacker yelled as he was wrestled to the ground after injuring two people.

Those words now have authorities exploring potential terrorism charges. In a Toronto courtroom on Tuesday, police charged Ayanle Hassan Ali, 27, with a litany of offences, including three counts of attempted murder.

Story continues below advertisement

Yet people who know Mr. Ali say he is not known as a violent fanatic. Rather, the Canadian Muslim of Somali heritage has become increasingly erratic and withdrawn. Lately, he has been given to talking about conspiracy theories, more about the Illuminati than Islam.

In cases like this, police and prosecutors are finding that religious motivations and a precarious mental state can mix in the minds of the same suspects. This creates questions about motivation and culpability, and whether crimes can truly be considered terrorism.

"I think there's a lot of assumptions made that people who are mentally ill can't also be radicalized, but people can experience both. That link isn't mutually exclusive," said Amarnath Amarasingam, a terrorism researcher at the University of Waterloo. "The question is," he added, "where do you place the emphasis?"

Mr. Ali is alleged to have claimed that he received direction from God. But no religiously literal Muslim claims such a thing. According to the Koran, even the Prophet Mohammed was never spoken to directly by God.

Story continues below advertisement

"Conservative Muslims talk to God. God doesn't talk back," Dr. Amarasingam explained. "To say, 'Allah told me to do this,' is quite a weird way to word the inspiration."

While Mr. Ali prayed at Rexdale mosques in north Toronto frequented by Somali Muslims, he was not particularly well known there. Several members of the community say he was a promising former university student until his family's struggles with mental-heath issues began to affect him.

Sohail Bagel, a caretaker at the mosque, said Mr. Ali came two or three times a week for prayer, but kept to himself. "He comes to pray and that's it.… He says nothing to nobody," Mr. Bagel said.

Abdifatah Warsame, a youth mentor in northwest Toronto, said the young man changed drastically after moving back in with his mother about five years ago. He said Mr. Ali had started to "isolate himself" and talk about the Illuminati – a mythologized secret society – controlling the world's poor.

Story continues below advertisement

Those who knew him were worried about the young man's transformation. He finished high school with honours before pursuing an engineering degree in Calgary, but he did not complete it, according to friends. Several community members say Mr. Ali's mother was herself paranoid about being hunted by U.S. government agents.

At a news conference on Tuesday, Toronto police Chief Mark Saunders said the suspect was born in Montreal and has lived in Toronto since 2011. He was not previously known to police.

In addition to three counts of attempted murder, he is charged with two counts of assault with a weapon, two counts of aggravated assault, one count of assault and one count of possession of a weapon for a dangerous purpose.

The chief said his force is working with federal investigators – including the RCMP and the Canadian Security Intelligence Service – to see if Anti-Terrorism Act charges can be laid. But such investigations are painstaking, he cautioned. "It's a slow-moving process," the chief said, adding that the wider public should not rush to any judgments. "One of the things I want to be very, very careful of, when it comes to the national security piece, that we don't go through that Islamophobia nonsense."

Story continues below advertisement

Terrorist offences rest on prosecutors being able to prove a crime was committed "for a political, religious or ideological purpose." University of Ottawa law professor Craig Forcese said that making a remark about "Allah" in the course of a stabbing would not likely be sufficient, in itself, to prove such motives.

Asked whether the events described by Toronto police amount to a terror attack, a retired CSIS analyst said it is likely too early for anyone to say definitively. "We don't know," Phil Gurski said, adding that "there are more questions than answers here."

The soldiers who were attacked – identified in court documents as Ryan Kong, Jesus Castillo and Tracy Ann Gerhardt – have been released from hospital. "They are okay," said Captain Rony Khalil, a spokesman at the recruiting centre. "The injuries were very minor."

Police say Mr. Ali was taken to hospital for examination because he was unresponsive after being apprehended. He has since been released to police custody.

The case bears some parallels to the events of October, 2014, when two extremists killed two Canadian Forces soldiers in attacks two days apart. Both suspects were shot dead by police.

Story continues below advertisement

In a speech in Ottawa earlier this year, RCMP Commissioner Bob Paulson spoke about how the difficulties of such cases like those were compounded by questions about the suspects' mental states. "I'm very aware that a big chunk of our vulnerable potentially radicalized people in Canada may have mental-health issues," he was quoted as saying at the time. "But let's find them, and let's help them, before we have to find them and arrest them or get into a shootout with them."

With reports from Tu Thanh Ha, Jill Mahoney and The Canadian Press