U.S. prosecutors had asked for a life sentence for Abdulrahman El Bahnasawy, who pleaded guilty to working with ISIS to attack Times Square and the New York subway system.
The defence, meanwhile, had asked for leniency, depicting the 20-year-old as an isolated, mentally ill addict who, with treatment, could “grow old in peace in Canada.”
“Today’s sentence reflects the severity of his conduct and holds him accountable for his terrorist activities,” Assistant Attorney General John Demers said in a statement.
The family’s lawyer, Denis Edney said Elbahnasawy’s mother, Khdiga, was removed from the courtroom after learning the sentence.
“Khdiga shouted at the judge and was taken out of the courtroom,” Edney said.
WATCH: Canadian caught in ISIS terror probe
The judge told El Bahnasawy he was “doing him a favour” by sentencing him to 40 years, Edney said.
While there’s no requirement for the US Bureau of Prisons to do so, the judge said he would do his best to make sure El Bahnasawy was placed in a prison that provided proper mental health treatment, Edney said.
The plot spanned four countries but the FBI successfully infiltrated it and arrested El Banhasawy in New Jersey in May 2016 following an undercover operation.
“In the name of ISIS, Abdulrahman El Bahnasawy planned an elaborate attack to wreak havoc and destruction on New York City,” U.S. Attorney Geoffrey Berman said.
“He planned to detonate bombs in Times Square and the New York City subway system, and to shoot civilians at concert venues.”
While he pleaded guilty to seven counts of terrorism, his family and lawyers said he had been in an out of treatment centres and blamed the undercover agent for contributing to his radicalization.
WATCH: Parents of Canadian caught in ISIS terror probe describe son’s history of mental illness and drug addiction
El Bahnasawy was born in Kuwait and moved to Ontario with his parents as a child. Beginning at age 14, his parents sent him to drug treatment centres in Kuwait, Toronto and Egypt.
Following his release from an Egyptian treatment program in 2015, he returned to Canada and became fixated with online Islamist extremism.
From his bedroom in his parents’ suburban Toronto home, he began corresponding with Abu Saad al-Sudani, a “high-level ISIS recruiter and attack planner” in Syria, according to prosecutors.
“He was exceptionally vulnerable to ISIS messaging,” his lawyers argued. “Isolated, he found a friend in the undercover agent, who praised his worst ideas and was instrumental in bringing them closer to reality.”
Prosecutors said the portrayal of Banhasawy as a vulnerable, weak victim “could not be further from the truth” and called him “dangerous and calculating,” with a “steadfast desire to kill.”