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 Wednesday 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 and that a lawyer and German consular staff will have access to him in detention.
The man arrived in Germany as an asylum seeker amid a large influx of refugees in August 2015, having already lived in the EU country for a decade until several years earlier.
Tunisia issued a warrant for his arrest in June 2016, and he was detained in Germany in August of that year.
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.
He was held on suspicion of recruiting for the Isis jihadist group with the goal of staging an attack in Germany.
Authorities on March 9th ordered his deportation.
On March 22nd, 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 Wednesday 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.
The case heightened tensions between Berlin and Tunis after it emerged red tape had prevented Amri's scheduled deportation months before the attack.