Mohamed Harkat, 44, was first detained in 2002 on suspicion of links to the global terror network and spent nearly four years in jail under a rarely-used national security measure before being released under strict bail conditions.
Harkat has denied terror links, claiming he fled Algeria over a crackdown on a political party to which he belonged, the now-defunct and banned Islamic Salvation Front (FIS).
The justices said in the decision that the "impugned provisions of the (anti-terror law) are constitutional."
Lower courts had ruled Harkat was likely an Al-Qaeda sleeper agent and a security threat.
More From This Section
His lawyers challenged the constitutionality of the so-called security certificates used against their client. They allow secret court hearings and indefinite jailing without charge of foreigners suspected of terror ties.
Canadian lawmakers have said the measures are necessary to thwart possible terrorist attacks. But critics argued they violate civil liberties.
The hearing was the first major test of Canada's revised security law since the original was struck down in 2007 as unjust and parliament rewrote it to ensure better legal representation of defendants.