Catalan police said they had killed four people to foil a second attempted attack, hours after a van ploughed into people in Barcelona, killing 13.
The force said that the shootings were linked to an imminent terror attack in Cambrils, a small port town around 70 miles south of Barcelona. A number of police officers were also reportedly injured during the operation
A suspected imminent terror attack in the town prompted them to launch the operation, the force said in a tweet.
A spokeswoman for the force said that officers shot dead four alleged perpetrators and injured one more during the raid.
Spain's public broadcaster, RTVE, is reporting that the suspects may have been carrying suicide explosive belts, although police did not confirm this.
It added that the suspects tried to carry out a similar attack to the one in Barcelona, when a van ploughed into people on Las Ramblas, killing 13 and leaving scores more injured.
It said seven people were injured by the suspects, two seriously.
The channel ran a video of Cambrils' promenade in which volleys of gunshots could be heard while sirens wailed and people's screams could be heard.
Catalan president Carles Puigdemont thanked police involved in the operation in these "critical and tragic hours".