Police on Friday hunted for the driver who rammed a van into pedestrians on an avenue crowded with tourists in Barcelona, leaving 13 people dead and more than 100 injured, just hours before a second assault in a resort along the coast.
Police said they killed five "suspected terrorists" during the night in the seaside town of Cambrils, 120 kilometres south of Barcelona where by-standers and police were injured in a second car attack.
Three others were arrested in other parts of the Catalonia region where both cities are located, but the driver responsible for the carnage in Barcelona remained at large, authorities warned.
The attacks are the latest in a wave of such assaults in Europe where vehicles have been used as weapons of terror.
In the Barcelona incident, claimed by the Islamic State group, a white van sped down a wide avenue packed full of tourists on Thursday afternoon, knocking people down and killing 13 in a scene of chaos and horror.
The driver left the vehicle and fled on foot.
Some eight hours later in Cambrils, an Audi A3 car rammed into pedestrians, injuring six civilians -- one of them critical -- and a police officer, authorities said.
Gunfire ensued during which police killed the five attackers. Some were wearing what appeared to be explosive belts, although Catalan interior minister Joaquim Forn later said they were fake.
United in grief
Witnesses in Barcelona recounted how bodies were strewn along the famous Las Ramblas boulevard where the driver went on a rampage as other people fled for their lives, screaming in panic.
As world leaders united in condemning the carnage, the IS propaganda agency Amaq claimed that it was carried out by "soldiers" from the jihadist group.
Police announced the arrest of three suspects, including a Spaniard and a Moroccan.
Carles Puigdemont, president of the region of Catalonia where both cities are located, warned the suspect still on the run was potentially dangerous, saying "these types of people have already demonstrated they have the will to harm whatever happens."
There were at least 18 nationalities among the Barcelona victims who came from countries as varied as France, Venezuela, Australia, Ireland, Peru, Algeria and China, according to Spain's civil protection agency.
Belgium said one of its citizens had died in the Las Ramblas assault, while the France's foreign minister said 26 French nationals were injured, 11 seriously, The Hague said three Dutch were injured and a Greek diplomat reported three nationals had been wounded -- a woman and her two children.
"We're united in grief," Spanish Prime Minister Mariano Rajoy said in a televised address after rushing to Barcelona, the biggest city in Catalonia, a region in Spain's northeast whose separatist government is defying Madrid with a drive for independence.
Whole street started to run
Las Ramblas is one of Barcelona's busiest streets, lined with shops and restaurants and normally packed with tourists and street performers until well into the night.
"When it happened I ran out and saw the damage," local shop worker Xavi Perez told AFP.
"There were bodies on the ground with people crowding round them. People were crying. There were lots of foreigners.".
In Cambrils, meanwhile, Markel Artabe, a 20-year-old restaurant worker, said he was on the seaside promenade when he heard what he initially thought were fireworks, but soon realised were gunshots.
He said he saw a person lying on the floor "with a gunshot in the head. His friends were crying out 'help'."
Europe's deadliest attack
Spain, the world's third most popular tourism destination, had until now been spared the kind of extremist violence that has rocked nearby France, Belgium and Germany.
It had even seen a surge in tourists as visitors fled other restive sunshine destinations like Tunisia and Egypt.
But it is no stranger to jihadist attacks, having been hit by what is still Europe's deadliest in March 2004, when bombs exploded on commuter trains in Madrid, killing 191 people in an attack claimed by Al Qaeda-inspired extremists.
It also had to deal with a decades-long campaign of violence waged by Basque separatist group ETA, which only declared a ceasefire in 2011.
Police said Thursday that one of the arrested suspects in the Barcelona attack was a Spaniard born in Melilla, a Spanish territory in North Africa, and the other a Moroccan named as Driss Oukabir.
In a further twist, the Spaniard was arrested in Alcanar, about 200 kilometres south of Barcelona, the scene of an explosion in a house late Wednesday that left one person dead and seven wounded and is believed to be linked to Thursday's assault.
"We suspect that they (the occupants) were preparing an explosive device," Josep Lluis Trapero of the regional Catalonia police told reporters.
Thursday's attack drew condemnation from across the globe, from US President Donald Trump to French leader Emmanuel Macron, whose country has witnessed a series of bloody jihadist atrocities including a truck rampage in Nice in July 2016 that killed 86 people.
The Nice carnage and other assaults including the 2015 shootings and bombings on Paris nightspots were claimed by the Islamic State, but it is believed to be the first IS claim of an attack in Spain.
Catalonia has the highest concentration of radicalised Islamists in the country along with Madrid and the Spanish territories of Ceuta and Melilla that border Morocco.