TORONTO - A Pakistani man inspired by Islamic State planned to attack the US consulate in Toronto and other targets in the city’s financial district but was caught when he shared his plan with an undercover police officer, Canada’s immigration authorities said on Wednesday.

Jahanzeb Malik, 33, was arrested on Monday after an undercover Royal Canadian Mounted Police officer befriended him as part of a long investigation into the former student, who has a record of travel to Pakistan and allegedly underwent combat training in Libya.

“He told the undercover officer about his plan to build remote controlled bombs to blow up the US consulate and other buildings in the financial district in Toronto,” the Immigration and Refugee Board of Canada said in an email.

Malik, who came to Canada as a student in 2004 and became a permanent resident in 2009, also told the undercover officer of his plans to make a video of the bombings to encourage others to do the same. “Mr Malik attempted to radicalise the undercover officer by showing him videos, apparently of ISIL beheadings,” the agency said. Malik is being detained by the Canada Border Services Agency (CBSA) and has not yet been charged with any criminal offences. The accusations have not been proven. The Canadian government is seeking to deport Malik as a security threat and the hearing at the Immigration and Refugee Board on Wednesday was held to determine whether he should be detained during the deportation process, which can take months.

Another Pakistani man suspected of militant links, Muhammad Aqeeq Ansari, is being held awaiting possible deportation.

According to AFP, Malik also allegedly took weapons, combat and landmine training in Libya, and told the officer he was “a personal friend of Anwar Al-Awlaki, an American citizen and top Al-Qaeda leader in Yemen, who was blown up by a US drone in 2011.”

Public Safety Minister Steven Blaney said outside parliament: “I cannot comment on operational matters but the RCMP has clearly indicated that this individual was willing to commit a terrorist attack on Canadian soil.”

“He was also promoting jihadi ideology,” the minister added.

Determined by the Immigration and Refugee Board to be a security and flight risk, Malik was ordered held pending his deportation.