The decision from the federal court of appeal on Friday removes a hurdle to the deportation of the suspect, Adil al-Sharqawi, a Moroccan whom the government suspects of engaging in so-called terrorist activities or planning to do so.
It also reinforces the government's position that it needs to have the right to hold people such as al-Sharqawi without trial to protect Canada's safety, particularly after the 11 September 2001 attacks on the United States.
"It is no exaggeration to say that the [al-Sharqawi] position completely ignores the issue of national security," the court ruled.
The decision did not state how or if al-Sharqawi had posed a threat to Canada.
Al-Sharqawi, who won permanent resident status in Canada in 1995, had argued that the government had no right to detain him under a security certificate - a security device that allows detention without trial under certain circumstances.
He has been under arrest since May 2003.
The Canadian government said senior al-Qaida lieutenant Abu Zubaida had reported seeing al-Sharqawi in Afghanistan in 1993 and between 1997 and 1998. Another operative said he trained with him in Afghanistan in 1998.
Right to liberty
The court said the individual right to liberty lost its meaning when "the society charged with ensuring its protection has lost its own right to liberty and security as the result of terrorist activities".
Johanne Doyon, al-Sharqawi's lawyer, had argued that it was unfair to hold him without trial and without being able to see or challenge some of the evidence against him.
She said he would probably seek to appeal against this decision in the supreme court.
Al-Sharqawi, who remains in a Montreal prison, is also involved in other court proceedings revolving around whether his security certificate is merited and if he could face torture if Canada returned him to Morocco.
The government says it has only used security certificates 27 times since they were introduced in 1991. Besides al-Sharqawi, three other suspects are being held under the detention without trial law, for allegedly having ties to Usama bin Ladin.