Abdeluahid Sadik Mohamed, born in the Spanish city of Ceuta, was remanded in custody by a court in Madrid pending investigation.
He was arrested on Sunday at Malaga airport in a sting operation carried out by Spain's police and Civil Guard forces.
He is accused of fighting as a jihadist in both Iraq and Syria.
Spanish authorities consider Sadik Mohamed a threat to national security, Spain's interior ministry said in a statement. He will now face charges in Madrid.
The suspect left Casablanca, Morocco in May 2013 and then travelled to Syria where he trained with the Al-Qaeda-linked Islamic State of Iraq and the Levant (ISIL), the interior minister said.
ISIL kidnapped Spanish journalists Javier Espinosa and Ricardo García Vilanova in September and is currently holding them hostage, Spain's El Mundo newspaper reported in December.
A third Spanish journalist, Marc Marginedas, may have also been captured by ISIL in September, although no group has claimed responsibility.
Sadik Mohamed is a member of a Spanish–Moroccan terror network based in Ceuta and the Moroccan town of Fnideq.
The group recruits and indoctrinates potential jihadists before organizing and paying for their travel to the Middle East.
The group was partially dismantled in a raid in Ceuta in June 2013.