Police said the men were linked to the Barcelona attack, which so-called Islamic State said it had carried out.
Police are still hunting the man who drove his van into crowds on Las Ramblas in Barcelona on Thursday.
Spanish media have named Moussa Oubakir, 18, as the suspect.
He is the brother of Driss Oubakir, whose documentation was allegedly used to rent the van involved in the attack.
Spanish PM Mariano Rajoy has condemned what he called a "jihadist attack". He has announced three days of national mourning and a minute's silence was held at noon (10:00 GMT) on Friday.
Seven people, including a police officer, were wounded when a car was driven into them early on Friday, Catalan emergency services said. One later died in hospital.
The attackers' vehicle overturned and when the men got out they were quickly fired upon by police, media say. One was reportedly brandishing a knife.