A group of 12 jihadists has been blamed for a series of attacks in and around the Spanish city of Barcelona, killing 16 people.
Four men have been arrested in connection with the attack.
A van mowed down tourists and residents on Barcelona's famous Las Ramblas boulevard on 17 August. Then a car was driven into pedestrians in the popular seaside resort of Cambrils. For days, suspected Ramblas attacker Younes Abouyaaqoub was on the run before police shot him dead.
At 16:50 (14:50 GMT) on 17 August a white van zig-zagged down Las Ramblas at high speed, while the pedestrian avenue - 1.2km (0.75 miles) long - was packed with tourists.
Witnesses said the driver tried to hit as many people as possible. Many were knocked to the ground while others fled for cover in nearby shops and cafes.
The driver killed 14 people and injured more than 100, then fled on foot.
Catalan police and medics were quickly on the scene. The police described it as a terror attack and later said one man had carried it out. They named him as Younes Abouyaaqoub, 22.
Eight hours later, a black Audi A3 car ploughed into pedestrians at Cambrils, 100km (62 miles) down the coast from Barcelona. A Spanish woman was killed.
The Audi overturned and five people got out, some wearing fake suicide belts. Four were shot dead by a policeman at the scene. A fifth escaped but was later shot dead.
The sequence of events
It has since become clear the attacks on Las Ramblas and at Cambrils were among several linked events that began the night before at Alcanar, further down the coast from Cambrils.
Two of the suspected jihadists were killed in an explosion at a house there shortly after 23:00 on Wednesday night. One was imam Abdelbaki Es Satty, a Moroccan believed to have been the ringleader. The other was believed to be Youssef Aallaa.
A third - Mohamed Houli Chemlal - was injured, and is among the arrested. He is being held by Spanish authorities on suspicion of terrorism-related offences.
The blast destroyed the house. Police found 120 gas canisters in the wreckage and now believe the house was being used as a bomb factory and headquarters by the jihadists.
Catalan police reckoned that the jihadists had been preparing bigger attacks, and that the accidental blast forced them to adopt a more rudimentary plan - the van rampage.
Houli Chemlal confirmed that that was the case, judicial sources said. He told the Madrid court on 22 August that Barcelona's iconic Sagrada Familia church was among the targets, the sources said.
All four suspects have reportedly said the ringleader of the group was the imam, Abdelbaki Es Satty. He and most of the suspects lived in Ripoll, a picturesque small town north of Barcelona.
CCTV footage showed suspected Las Ramblas attacker Younes Abouyaaqoub leaving the scene of the van murders and walking through La Boqueria market.
Reports suggest he then headed to the city's university area where he hijacked a white Ford Focus car at knifepoint and killed the driver, Pau Pérez. He then crashed through a police checkpoint, breaking a policewoman's leg, as he tried to leave Barcelona.
The car was found abandoned a few kilometres to the south, at Sant Just Desvern, with the body of Mr Pérez on the back seat. He had been stabbed - the 15th victim of the Barcelona and Cambrils attacks.
Abouyaaqoub went on the run. On 21 August, police were tipped off by members of the public who had seen a man of his description in the rural Subirats area, 40km west of Barcelona. Police were on the scene and within minutes the suspect, wearing a fake explosives belt, had been shot dead.
Who are the main suspects?
Younes Abouyaaqoub, the suspected van driver, born in Morocco. He was among the jihadists who lived in Ripoll, 100km north of Barcelona.
Imam Abdelbaki Es Satty, 45, died in the Alcanar blast. He lived in a modest flat in Ripoll. Belgian officials say he spent three months living in Machelen, a suburb of Brussels, before the March 2016 suicide bombings that killed 32 people in the Belgian capital.
In 2010-2014 he was in jail in eastern Spain for drug trafficking, police said.
Satty was described by locals in Ripoll as a reclusive, devout Muslim who was close to the Moroccan youths. The father of two of the Cambrils attackers has accused him of radicalising them.
Driss Oukabir, 28, is among the men charged in relation to the attack. He denied being in the jihadist cell but admitted having hired two vans, one of which was used in the Barcelona attack. He said he hired them thinking his friends would use them for a house move.
Police found his passport in the Barcelona van - he claimed that his brother Moussa Oukabir, 17, had stolen his ID. The younger brother was among the five killed by police in Cambrils. The other van was later found in the town of Vic and believed to be a getaway vehicle.
Driss turned himself in in Ripoll on 17 August, with a judge ordering him detained on suspicion of terrorism-related offences on 22 August. The Oukabir brothers had Moroccan as well as Spanish nationality.
The other four attackers killed at Cambrils were Said Aallaa, 18; Mohamed Hychami, 24; Omar Hychami and Houssaine Abouyaaqoub. Said Aallaa is said to have left a note in his room apologising for the harm he was about to cause.
Who else has been arrested?
Two other men were detained in Ripoll - Salah el-Karib, 34, and Mohammed Aallaa, 27. The latter is believed to be the owner of Audi car used by the jihadists in Cambrils. He has been released on conditional bail as there is not enough evidence to hold him, court papers revealed.
A judge ordered el-Karib to be held for a further 72 hours to allow investigators more time.
French police say the Audi was driven to Paris by Younes Abouyaaqoub and another jihadist on a short weekend trip before the Barcelona attack. Their motive for that is not clear, but they are known to have gone shopping.
Who are the victims?
They come from all over the world, with at least 34 nationalities represented.
People from Ireland, the UK, France, Australia, Pakistan, Venezuela, Algeria, Peru, Germany, the Netherlands, Greece, Hong Kong, Taiwan, Ecuador, the US, Argentina, Romania, Cuba, Austria and the Philippines are all reported to be among those hurt.
These names of the dead have so far been released:
- American Jared Tucker, 43
- Belgian Elke Vanbockrijck, 44
- Spanish-Argentine Silvina Alejandra Pereyra, 40
- Argentine Carmen Lopardo, 80
- Spaniard Pepita Codina, 75
- Canadian Ian Moore Wilson
- Spaniard Francisco López Rodríguez, 57. A three-year-old relative with him also died
- Italian Bruno Gulotta, 35
- Italian Luca Russo, 25
- British-Australian national Julian Cadman, 7
- Spaniard Ana María Suárez. Died in the Cambrils attack
- Pau Pérez, 34, found fatally stabbed in car at Sant Just Desvern
Two Portuguese nationals are also confirmed dead, a woman aged 74 and her 20-year-old granddaughter.
An unnamed German woman, 51, died in hospital on 27 August.
Jared Tucker, a father-of-three, was on honeymoon with his wife of one year, Heidi Nunes, when he died, his father said. Mr Tucker had been enjoying drinks on Las Ramblas when the van struck him.
Ian Moore Wilson was the father of a Vancouver police officer. His wife, Valerie, was injured.
The mother of Julian Cadman, the seven year old killed on Las Ramblas, was also injured in the attack and is in a serious but stable condition in hospital.
Was a bigger group behind the attack?
So-called Islamic State (IS) has said it was behind both the Las Ramblas and Cambrils attacks and that IS "soldiers" carried them out. But it did not provide any evidence or details to back up the claim.
Spain is one of Europe's most popular tourist destinations, but in recent years has not seen the kind of jihadist violence that has rocked France, the UK, Belgium and Germany.
Still, Spain has been targeted before - several trains in Madrid, the capital, were bombed by al-Qaeda inspired militants in 2004, killing 191 people and injuring hundreds of others. It remains Europe's bloodiest terror attack this century.
IS news outlet Amaq said the attack was carried out as part of efforts to target states fighting in the US-led anti-IS coalition.
A few hundred Spanish soldiers are in Iraq, training local forces fighting IS.
The number of operations carried out against jihadists in the country has increased significantly since Spain raised its terror alert level to four out of five in June 2015, meaning there was a "high risk" of a terror attack.
Security was stepped up in the wake of truck attacks in the French city of Nice in July 2016 and the German capital Berlin in December.
On Twitter, the Spanish royal household posted: "They are murderers, nothing more than criminals who are not going to terrorise us. All of Spain is Barcelona."