The man -- identified only as Haykel S, 36, by local media -- has been named in Tunisia as a suspect behind the Bardo Museum attack that killed 21 foreign tourists and a police officer.
A Frankfurt court said today it had rejected a last-ditch asylum request, but set conditions for his deportation.
It ruled that Tunisia must "assure the German government" that he won't face the death penalty or ill-treatment in custody at that a lawyer and German consular staff will have access to him in detention.
Tunisia issued a warrant for his arrest in June 2016, and he was detained in Germany in August of that year.
More From This Section
However, Tunisia then failed to provide the required documentation for his deportation on time, German officials say.
Authorities were forced to release him in November 2016, but security services kept him under surveillance.
The man was arrested again in February as part of sweeping anti-terror raids in the Frankfurt area on homes, offices and mosques.
Authorities on March 9 ordered his deportation.
On March 22, as he was about to board a flight, the man launched a last-minute request for asylum, citing the threat of torture and the death penalty in Tunisia, while proclaiming his innocence.
Two days later German immigration authorities rejected the asylum request as unfounded, a decision the man then appealed. The Frankfurt court today upheld the denial of asylum.
Last December, another Tunisian rejected asylum seeker, Anis Amri, committed Germany's worst jihadist attack so far, ploughing a truck through a Berlin Christmas market and taking 12 lives.