Connect to share and comment
They arrested Mohamed Echaabi, a man "of Moroccan origin", on Thursday in the eastern city of Valencia, a police statement said.
It said he had "the same profile" as Mohammed Merah, a radicalised French Algerian who shot dead seven people including three children in a Jewish school in Toulouse last March.
Echaabi had travelled to Gaza in 2011 and was later caught trying to buy guns and explosives, police said.
"Police consider Echaabi a lone wolf, recruited by terrorist networks and self-radicalised via the Internet," the statement said.
"Police surveillance and the activities he carried out revealed his intention to commit terrorist acts against certain people and other targets, in accordance with the doctrine of global jihad, in Spain and other European countries," it added.
Several suspected Islamic extremists have been arrested in recent years in Spain, which in 2004 suffered one of Europe's worst extremist attacks.
On March 11, 2004, bombs exploded on packed commuter trains in Madrid, killing 191 people and wounding 1,841 others in attacks linked to the Al-Qaeda network.
Twenty-one people, mostly Moroccans, were convicted of involvement in those attacks.
In March, police in Valencia arrested Mudhar Hussein Almalki, a Saudi dubbed "Al-Qaeda's librarian". He was suspected of running jihadist Internet forums and sharing documents with extremists.
In August, Spanish authorities arrested two Chechens and a Turk, suspected Al-Qaeda members thought to have been planning an attack in Spain or elsewhere in Europe.
Two of them were caught on a bus heading for the French border and the third in the far southern town of La Linea de Concepcion, where police also discovered explosives.