The Guardia Civil said the man, a Moroccan citizen, was arrested in the Catalan capital following a surveillance operation.
The police force said in a statement that the man appeared to have been radicalised and linked to Isis for at least four years, but had kept a low profile online and offline until recently.
Investigators, however, noticed a “striking and worrying” change in his behaviour during the state of emergency declared by the Spanish government in response to the coronavirus, and became concerned that he was preparing to respond to Isis calls to carry out attacks in the western countries.
“Since the coronavirus began spreading across Europe, there have been a number of single-person terrorist attacks involving knives or vehicles,” the statement said.
“The arrested man had used social media to proclaim his loyalty to Isis and his hatred for the west. Surveillance officers noticed that he had begun to disregard the lockdown rules set out in the state of emergency on a regular basis, and that he was taking important security measures as he ventured around Barcelona, suggesting he was carrying out a possible search for targets.”
The man had become “totally influenced by Isis propaganda” and had sworn loyalty to the group, “raising real security fears”.
Sixteen people were killed in terrorist attacks in Barcelona and the Catalan coastal town of Cambrils in August 2017.
Thirteen of the victims died and more than 100 were injured when a man drove a van down the busy La Rambla shopping street in Barcelona, mowing down pedestrians.
It emerged later that the terrorist cell behind the atrocity was planning a much larger attack, including bombing the city’s famous Sagrada Familia church.
Spain suffered its worst terrorist attack in 2004, when 191 people were killed and more than 1,800 injured in a series of explosions on four crowded commuter trains in Madrid.
Two weeks ago, Spanish police arrested a former British rapper turned Islamic State extremist, Abdel-Majed Abdel Bary, one of the most wanted militants in Europe.
British and other sources confirmed his identity a few hours after the national police force in Madrid said it had arrested an Egyptian national and two other men in a flat in the southern city of Almería.