Spanish police shot dead five would-be attackers after confronting them early on Friday in a town south of Barcelona where hours earlier a suspected Islamist militant drove a van into crowds, killing 13 people and wounding scores of others.
Islamic State said the perpetrators had been responding to its call for action by carrying out Thursday's rampage along Barcelona's most famous avenue, which was thronged with tourists enjoying an afternoon stroll at the peak of the summer season.
Bodies, many motionless, were left strewn across the avenue and authorities said the toll of dead, which included several children, could rise, with more than 100 injured.
Hours later in the early hours of Friday, as security forces hunted for the van's driver, police said they killed five suspects in Cambrils, 75 miles south along the coast from Barcelona, to thwart a separate attack.
The five men attempted to drive into tourists on the Cambrils seafront, police said. Their car overturned and some of them began stabbing people. Four were shot dead at the scene and the fifth was killed a few hundred meters away, police said.
Police said they had arrested a Moroccan and a man from Spain's north African enclave of Melilla, though neither was the driver of the van. He was seen escaping on foot and was still at large. A third man was arrested in the town of Ripoll on Friday.
Police said later they had made a fourth arrest in connection with the attacks but gave no details.
A Spanish woman was killed in the Cambrils incident while several other civilians and a police officer were injured. Police destroyed explosive belts the men had been wearing, though they turned out to be fake.
Of the 130 people injured in both attacks, 17 were in a critical condition and 30 were serious, an emergency services spokesman said.
Shortly before midnight on Wednesday, the day before the van plowed into the tree-lined walkway of Barcelona's Las Ramblas avenue, one person was killed in an explosion in a house in a separate town southwest of Barcelona, police said.
A judicial source said investigators believed a cell of at least eight people, possibly 12, may have been involved in the Barcelona and Cambrils operations and that it had been planning to use gas canisters.
Later on Friday, residents and tourists returned to Barcelona's famous Las Ramblas promenade where hours earlier a white van had zigzagged at high speed through pedestrians and cyclists, leaving bodies and injured writhing in pain in its wake.
The injured and dead came from 34 countries, ranging from France and Germany to Pakistan and the Philippines, Catalan emergency services said. Spanish media said several children were killed.
As Spain began three days of mourning, people laid flowers and lit candles in memory of the victims along the promenade. Prime Minister Mariano Rajoy and Spain's King Felipe visited Barcelona's main square nearby to observe a minute's silence.
Defiant crowds later chanted "I am not afraid" in Catalan.
Islamic state claim
Islamic State's Amaq news agency said the attackers had carried out the operation "in response to calls for targeting coalition states" – a reference to a US-led coalition against the Sunni militant group. Spain has several hundred soldiers in Iraq training local forces in the fight against Islamic State.
There was no immediate indication though that Islamic State had directed or organized the attack, although some of those responsible for similar attacks in Europe have been inspired by the jihadist group.
Islamist militants have staged several attacks across Europe in the past 13 months, killing over 100 people in Nice, France; Berlin; London; and Stockholm.
In March 2004, Islamist militants placed bombs on commuter trains in Madrid, killing 191 people.
Victims represent many nations
Police said the two men detained on Thursday had been arrested in two towns, Ripoll and Alcanar, both in the region of Catalonia, of which Barcelona is the capital.
The explosion was also in the town of Alcanar. One person died and another was injured in that incident, police said.
A man was also found dead in a car which had driven into a police checkpoint in Barcelona, though the police could not immediately confirm it was connected with the van attack.
German Chancellor Angela Merkel, speaking after media reports that some Germans were among those killed, said Islamist terrorism "can never defeat us" and vowed to press ahead with campaigning for a general election in Germany in September.
Last December, Berlin suffered a similar attack when a truck plowed into a crowded Christmas market, killing 12.
Italy said two of its nationals were killed and three injured while Belgium said one Belgian had died. German television channel ZDF reported three Germans among the dead.
France said 26 of its citizens were hurt, and 11 of them were in a serious condition. Australia said at least four of its nationals were injured, with broadcaster ABC saying a 7-year-old boy was unaccounted for.
A British Foreign Office spokeswoman said the ministry was assisting "a small number" of Britons.
Foreign leaders voiced condemnation and sympathy, including French President Emmanuel Macron, whose nation has suffered some of Europe's deadliest militant attacks.
In a message to the cardinal of Barcelona, Pope Francis said the attack was "an act of blind violence that is a grave offense to the Creator.
Polish Interior Minister Mariusz Blaszczak said the attack showed the European Union's system of migrant relocation was wrong. "It is dangerous. Europe should wake up," he said. "We are dealing here with a clash of civilizations."
Authorities in Vic, a small town outside Barcelona, said a van had been found there in connection with the attack. Spanish media had said that a second van was hired as a getaway vehicle.
Additional reporting by Sarah White, Andres Gonzalez, Silvio Castellanos, Alissa de Carbonnel, Ali Abdelaty and Ahmed Aboulenein, Kylie MacLellan. This story was reported by Reuters.