Thirteen people died and dozens were injured when a van ploughed into crowds in Barcelona’s famous Las Ramblas area, Catalan police and local officials say.
The rented vehicle sped along the pedestrian area that is popular with tourists, mowing down people and sending others fleeing for cover.
Spain’s Prime Minister Mariano Rajoy said it was a “jihadist attack”.
Two people have been arrested, but police say neither was the driver, who fled on foot.
Early on Friday morning, Catalan police said an operation was taking place in town of Cambrils, to the south-west of Barcelona, in response to a “possible terrorist attack” and have told people there to stay indoors.
The authorities also say an explosion on Wednesday evening at a house outside Barcelona that left one person dead was connected to the Las Ramblas attack.
Dozens of gas cylinders were found at the house in the town of Alcanar, about 100km (60 miles) south west of Barcelona, and Reuters quoted a police source as saying residents were preparing explosives.
In another incident, police shot dead a man who drove into officers at a checkpoint on the outskirts of Barcelona, but the authorities said there was no evidence that he was connected to the attack in Las Ramblas.