Canada's Supreme Court has struck down a controversial system that allowed the government to detain and deport foreign-born terror suspects.
The debate over the law pitched security against individual rights
The nine judges ruled that the security certificate system - in place since 1978 - violated Canada's Charter of Rights and Freedoms.
The system allowed a suspect to be held indefinitely or deported on the basis of evidence presented in secret.
The case was brought by three men who deny accusations of links to al-Qaeda.
The Supreme Court has given parliament one year to rewrite the section of the Immigration and Refugee Protection Act - under which the certificates are issued - to comply with the constitution.
"Before the state can detain people for significant periods of time, it must accord them a fair judicial process," wrote Chief Justice Beverley McLachlin on behalf of all nine judges.
The three men who brought the case to the Supreme Court - Algerian-born Mohamed Harkat, Moroccan-born Adil Charkaoui and Syrian-born Hassan Almrei - deny links to terrorism and said they would be tortured if they were deported to their native countries.
The three suspects said the law discriminated against them
The court said it was arbitrary to detain the men for a long period without a review of their circumstances.
Mr Harkat was held for three-and-a-half years without charge until he was freed on bail in June 2006 under strict conditions.
Mr Charkaoui spent 21 months in jail before he was freed in February 2005 also under strict bail conditions.
Mr Almrei has been detained since October 2001.
"It's a very good decision and we're certainly very pleased," said Mr Almrei's lawyer Barbara Jackman.
Two other men, both Egyptian-born, also face deportation under the security certificates, but were not part of the Supreme Court case.
Government ministers and security officials have said the certificates are necessary to defend national security.
But critics have said they lead to indefinite detention or deportation of non-Canadian citizens on the basis of secret intelligence presented to a federal court judge at closed hearings.
"The secrecy required by the scheme denies the named person the opportunity to know the case out against him or her, and hence to challenge the government's case," Justice McLachlin wrote.