Spanish authorities began their investigation after becoming aware just before Christmas that the “potentially dangerous” Algerian man was in Spain, police said in a statement.
The man, a “jihadist” who had fought for the Islamic State group in Iraq, was arrested at a building occupied by squatters in Barcelona's seaside neighbourhood of Barceloneta, the statement added.
Police detained two other Algerian men as part of the operation, one suspected of giving him “logistical support” in Spain and another described by police as has “acolyte”.
The operation was carried out in cooperation with European Union law enforcement agency Europol and the FBI, as well as the intelligence services of Spain and Algeria, the statement said.
The three men appeared before a court on Monday where the presiding judge ordered they be remanded in custody on suspicion of membership in a terrorist organisation.
Their arrest comes as the trial of three men accused of helping the jihadists behind the August 2017 attacks in Barcelona and a nearby town that killed 16 people is wrapping up at a court near Madrid.
The Islamic State group claimed responsibility for the attacks, one of which involved a van ramming people in the centre of Barcelona.
While none of the three men on trial are charged with direct responsibility, they are in the dock for helping the attackers, who were all shot dead by police.