Ontario's highest court has granted a new trial for two men who were found guilty of terrorism charges after being accused of plotting to derail a Via Rail passenger train in the Greater Toronto Area.

The Court of Appeal for Ontario ordered Tuesday that the 2015 convictions of Raed Jaser and Chiheb Esseghaier be set aside.

A new trial was ordered. The Public Prosecution Service of Canada confirmed in a statement that it will proceed with a new trial.

Both men are still in custody, and will remain there unless they are released on a successful bail application, said Megan Savard, one of Jaser's lawyers.

His lawyers had argued in court earlier this year that the judge who oversaw the case made several errors, including rejecting their request as to the method of jury selection.

You cannot fix a mistake that led to an improperly constituted jury. — David Butt, criminal defence lawyer

Savard told CBC News that her client is "grateful to the Court of Appeal for the chance at a trial in front of a jury chosen legally."

"The decision might be a bit hard for some people to get through, because there's a lot of technical language," she said.

"But the bottom line is the fair jury selection process is a hallmark of Canadian justice. Mr. Jaser has been in jail since 2013, and still hasn't had a trial in front of a jury that was chosen legally, so we think this is the right result."

Jaser and Esseghaier were found guilty in 2015 on a total of eight terror-related charges between them. They were originally sentenced to life in prison with no chance of parole until 2023.

The men were arrested in 2013, following a cross-border investigation that involved Canadian and American law enforcement.

RCMP said at the time the two accused were plotting to derail a passenger train. Police said in 2013 that the two men watched trains and railways in the Greater Toronto Area.

Police said in 2013 that Jaser and Esseghaier were getting "direction and guidance" from al-Qaeda elements in Iran.

Jury selection improper

The crux of the court's decision Tuesday to order a new trial is the way the original jury was selected. In documents filed in court earlier this year, Jaser's lawyers said the law regarding jury selection was in flux during the trial, but over time the interpretation used by the trial judge has been found to be wrong.

In an interview on CBC News Network Tuesday, criminal defence lawyer and former prosecutor David Butt said the grounds on which the new trial was ordered are "exceedingly technical."

The appeal in the case centres on the way the first trial's jury was selected. (Adrian Wyld/The Canadian Press)

"But underlying it is a critically important idea, and that is that everyone charged with a serious offence has a right to a trial by a properly constituted jury — and if the jury is improperly constituted, then everything they do afterwards is problematic," he said.

There had been significant media coverage before the trial, so the Crown and Jaser's lawyers determined that "challenges for cause" for prospective jurors were needed, according to the decision.

Each prospective juror was questioned about whether pretrial publicity and the fact that each of the men was a visible minority and Muslim would affect their ability to decide the case impartially.

Triers of fact key to appeal

When a potential juror is questioned during jury selection, "triers" are appointed to listen to their answers and help decide whether the person should sit on the jury. If the triers deem a prospective juror to be unbiased, the Crown and defence then have the final say on whether that person sits on the jury.

There are two varieties of triers in Canada's Criminal Code: rotating triers, who will serve on the jury and rotate out as additional jurors are sworn, or static triers, who hear and determine all challenges until the entire jury has been sworn, but do not themselves become members of the jury.

Jaser's legal team requested rotating triers, and for the court to exclude prospective jurors from the courtroom while challenges were heard to protect jury impartiality "by avoiding exposing unsworn jurors to other jurors' answers," the decision reads.

In the end, the trial judge ruled he could not exclude unsworn jurors during a challenge for cause that used rotating triers. He instead ordered that all jurors, unsworn and sworn, be excluded from the room and that static triers be used. The jury was picked using this process, and it tried the charges against both men.

In its decision, the court of appeal said it was "clear that [the judge] erred" by going this route.

"You cannot fix a mistake that led to an improperly constituted jury," Butt said.

adam.carter@cbc.ca