Abdeluahid Sadik Mohamed was detained at Spain's Malaga airport as a "threat to national security" after landing on a flight from Turkey.
Spain's Interior Ministry said in a written statement that Sadik Mohamed had been in Syria with the Islamic State of Iraq and Syria, which has close ties to al-Qaida and has imposed harsh Islamic law on territory it occupies.
Sadik Mohamed was specifically involved in terrorist training camps established by the Islamic State group in Syria and Iraq, the statement said.
Western intelligence agencies have been closely watching the movements of European citizens in Syria, Iraq and Afghanistan in order to head off potential "lone wolf" terrorists who could stage attacks inside Europe, CNN said.
Sadik Mohamed was linked to a militant network in Spain and Morocco that was training fighters to be sent to Syria. CNN said a Spanish judge last summer issued a court order stating the network was dedicated to sending jihadist fighters to Syria and had ties to another organization affiliated with al-Qaida that was urging the spread of terrorist attacks to Europe.