The men were linked to the Barcelona attack, police say.
Police are still hunting the man who drove his van into crowds on Las Ramblas in Barcelona on Thursday.
Spain's PM Mariano Rajoy described it as a "jihadist attack", which so-called Islamic State said it had carried out.
Mr Rajoy has announced three days of national mourning and a minute's silence will be held later 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 person is in a critical condition.
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.
The men were wearing explosive belts, police said, and a series of controlled explosions was carried out. The belts proved to be fake, Catalan regional head, Carles Puigdemont, later told local radio.
Police say the situation in Cambrils - a popular seaside resort 110km (68 miles) south-west of Barcelona - is now under control.
(BBC News)