A 30-year-old Ontario resident was denied bail on immigration charges after a lawyer for the Immigration Minister told a hearing he is an "integral" member of an extremist group based overseas.

Muhammad Aqeeq Ansari, a software designer living in Toronto, allegedly created and maintained a website for Ahl-e-Sunnat Wal Jamaat (ASWJ) – which is listed as a terrorist organization in Pakistan and the United Kingdom, but not in Canada.

Canadian officials are seeking to deport Mr. Ansari, a Pakistani citizen with permanent residency status in Canada, as a security threat, but he faces no Criminal Code charges.

Story continues below advertisement

Immigration and Refugee Board member Mary Lou Funston denied him bail after she considered the government's position that Mr. Ansari is a flight risk, a security threat and a danger to the public. She found that his "extremist views" and prior firearms-related charges raised a reasonable likelihood of him posing "a present and future danger to others."

Mr. Ansari watched via video from a jail in Lindsay, Ont.

His detention comes as federal security agencies step up their response to the threat of extremism after two Canadian soldiers were killed last week in separate attacks the government has called terrorism.

Mr. Ansari was first reported inadmissible to Canada on Aug. 8 this year but wasn't arrested until Monday. Many of the allegations against him stem from a police raid of his Peterborough, Ont., home on gun-related charges more than two years ago. Police discovered a thumb drive containing jihadi propaganda at that time. His lawyer, Anser Farooq, said police did not lay any other charges after investigating and questioned the timing of his client's arrest. "I suspect it's got a lot to do with what happened in Ottawa," Mr. Farooq said in an interview. "CSIS is under pressure; the RCMP is under pressure."

Mr. Farooq said he's heard from at least four other individuals who were recently contacted by the RCMP or Canadian Security Intelligence Service (CSIS) in what they described as a "confrontational" and "threatening" manner. Some had last connected with the authorities years ago.

Representing the Minister of Immigration, Jessica Lourenco told the hearing the thumb drive found at Mr. Ansari's home was the catalyst for an RCMP-led Integrated National Security Enforcement Team investigation of him. The Canada Border Services Agency is continuing that investigation.

When police raided the home in 2012, they found unsecured firearms and loose ammunition scattered in the basement, which was accessible to children, Ms. Lourenco said.

Story continues below advertisement

"Mr. Ansari has shown himself to be careless in regards to the safety of others," Ms. Lourenco said.

Mr. Ansari surrendered more than a dozen guns, including a Bushmaster Adaptive Combat Rifle. While the guns had been acquired legally, Ontario Provincial Police had charged him with storing them improperly.

Ms. Lourenco said Mr. Ansari also expressed extremist views on social media, such as a Facebook photo of a downtown high-rise with the caption "If only I had a plane."

There is no allegation that Mr. Ansari ever plotted or engaged in any acts of violence. But officials now say that the thumb drive included files labelled "Taliban" as well as songs that supported "Jihad."

Mr. Ansari's next bail hearing is scheduled for Nov. 7 at the Toronto Immigration Holding Centre on Rexdale Boulevard.