Judge Santiago Pedraz ordered Nouh Mediouni, 23, to be held in custody as a flight risk on charges of "membership of a terrorist organisation", according to a written ruling from the National Court.
Police arrested Mediouni, who is of Algerian origin, on Tuesday in the northern Spanish city of Zaragoza.
They said he had been in contact with Al-Qaeda in the Islamic Maghreb (AQIM), which has carried out attacks and kidnappings across north Africa.
The interior ministry said Mediouni was highly radicalised and was thought to have been recruited by Mali-based members of AQIM via an online militant forum.
Police in Murcia in the southeast on Tuesday arrested Hassan El Jaaouani, 52, of Moroccan origin, who they said had also been in contact with Mali-based AQIM leaders.
A judicial official said the judge on Friday released El Jaaouani on bail and ordered him not to leave Spain.
Interior Minister Jorge Fernandez-Diaz said the two suspects appeared to be "lone wolves" -- individuals who became radicalised despite not having previous links to organised groups.
The government said 13 people had been arrested in Spain for "international terrorism" since the current conservative government took office at the end of 2011.
On March 11th, 2004, Spain suffered one of Europe's worst terror attacks when explosions linked to Al-Qaeda killed 191 people on packed commuter trains in Madrid.
Twenty-one people, mostly Moroccans, were convicted of involvement in those attacks.