Germany's federal appeals court has upheld the acquittal of Abdelghani Mzoudi, a Moroccan who was accused of links to the 11 September attacks.
Abdelghani Mzoudi's 2003 trial in Hamburg collapsed
He was acquitted in February 2004 of charges that he helped the 11 September 2001 hijackers who attacked the US.
The appeals court ruled on Thursday that there was insufficient evidence to justify a retrial.
Hamburg authorities still want to expel Mr Mzoudi from Germany. But his lawyers say the asylum option is still open.
Another Moroccan, Mounir al-Motassadek, was jailed in connection with the 11 September attacks, which were carried out by the Hamburg cell of al-Qaeda. But his conviction was later quashed and a fresh trial was ordered.
A Hamburg interior ministry spokesman said Mr Mzoudi had 14 days to leave Germany voluntarily or be deported.
His lawyer Hartmut Jacobi, quoted by the Associated Press, said "he has not yet decided whether he will remain here".
Testimony at Mr Mzoudi's trial showed that he was a friend of lead hijacker Mohamed Atta and other members of the Hamburg cell.
Mr Mzoudi denied any knowledge of the plot, which resulted in the deaths of nearly 3,000 people.
Acquitting him in February 2004, the presiding judge described him as a "fringe figure" and said he was being freed because of insufficient proof against him - not because the court was convinced of his innocence.