An imam thought to be the ringleader in terror attacks that left 15 people dead was among those killed at an explosion in a house in the town of Alcanar, Spanish police have confirmed.

A van was used to kill 13 and injure more than 130 people in Barcelona on Thursday 17 August, one man was stabbed to death in a car outside the city and hours later another attack took place in the seaside town of Cambrils, leaving one person dead and 13 injured.

Police raided the home of Moroccan imam Abdelbaki Es Satty over the weekend, and he has now been formally linked to the 2004 Madrid train bombings. In addition, Es Satty had recently travelled to Belgium where he had spent three months at the time of the Brussels attacks.

Police are now investigating his role in radicalising the younger members of the group that carried out the atrocities.

Es Satty’s remains were found among those of at least three people who were killed at a suspected bomb-making factory in the town of Alcanar, about 120 miles south-west of Barcelona.

Police said about 120 butane gas cylinders were found at the house and believe he was plotting a much bigger attack, but the accidental explosion prompted the remaining group of militants to carry out a less elaborate plan.

Four people have been arrested in connection with the attacks so far, and today police shot dead Moroccan-born Younes Abouyaaqoub, 22, the man believed to have been at the wheel of the van that drove at high speed into crowds on Barcelona’s Las Ramblas.

Spanish police are not thought to have had the imam or other members of the terror cell under surveillance, despite Es Satty’s extremist connections and their prior knowledge of a period when he was in prison.

People who knew the imam said he was not religious until he was jailed for drug smuggling and breaking Spanish immigration laws.

Es Satty spent four years in prison, during which time he befriended Rachid Aglif, who was serving time for his part in the al-Qaeda-inspired Madrid bombings.

After his release from prison, he spent several months trying to find employment at mosques in Brussels’ Vilvoorde district in the north of the city.

Vilvoorde is known for Islamist activity, but when Belgian police were informed by locals of El Satty’s attempts to get work, and contacted the Catalan department of justice, they were told he had no links to extremist violence.

In 2015 Es Satty started teaching at one of the two mosques in Ripoll, the quiet Spanish town in the north-east of the country near to the French border and around 62 miles from Barcelona.

Ripoll was home to all of the main suspects in the attack.

The terrorists – whose number included a waiter, an extreme sports instructor and some Catalan speakers – were said by friends and relatives to have appeared to live normal lives until they started to attend Es Satty’s sermons.

A woman who knew several members of the group said the imam repeatedly preached about jihad and killing “infidels”, adding: “I feel like I could have done something. I feel a little bit guilty now.

“Everybody knew it. It was an open secret. But I can’t say it because these people are dangerous and they could come after me. I don’t trust anybody now.”

Catalonia is gaining a reputation as a centre of Islamist extremism, with the US State Department calling for a regional counter-terror hub to be set up there.

A Spanish think tank said that almost a third of Isis-linked arrests in Spain were now made there.

Of the main suspects, four have been detained, five killed by police marksmen following the attack in Cambrils, two have disappeared, three died in the explosion in the bomb making factory, including Es Satty, and the driver of the van, Abouyaaqoub, was caught in a Barcelona suburb and shot dead by police today.

As the investigation progresses, Spanish police can expect questions over how a group of more than a dozen militants was able to build a significant weapons factory and plan sophisticated terror attacks without being detected.

Barcelona Attack Show all 30 1 /30 Barcelona Attack Barcelona Attack Police officers patrol on Las Ramblas following yesterday's terrorist attack, on August 18, 2017 in Barcelona, Spain. Thirteen people were killed and dozens injured when a van hit crowds in the Las Ramblas area of Barcelona on Thursday. Spanish police have also killed five suspected terrorists in the town of Cambrils to stop a second terrorist attack Getty Images Barcelona Attack Tourists and locals walk along Las Ramblas following yesterday's terrorist attack, on August 18, 2017 in Barcelona, Spain. Thirteen people were killed and dozens injured when a van hit crowds in the Las Ramblas area of Barcelona on Thursday. Spanish police have also killed five suspected terrorists in the town of Cambrils to stop a second terrorist attack. Getty Images Barcelona Attack Police officers patrol on Las Ramblas following yesterday's terrorist attack, on August 18, 2017 in Barcelona, Spain. Thirteen people were killed and dozens injured when a van hit crowds in the Las Ramblas area of Barcelona on Thursday. Spanish police have also killed five suspected terrorists in the town of Cambrils to stop a second terrorist attack. Getty Images Barcelona Attack People leave a fastfood with hands up as asked by policemen after a van ploughed into the crowd, killing two persons and injuring several others on the Rambla in Barcelona on August 17, 2017. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least two people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack" and a police source said one suspect had left the scene and was "holed up in a bar". The police source said they were hunting for a total of two suspects AFP/Getty Barcelona Attack Police officers tell members of the public to leave the scene in a street in Barcelona, Spain, Thursday, Aug. 17, 2017. Police in the northern Spanish city of Barcelona say a white van has jumped the sidewalk in the city's historic Las Ramblas district, injuring several people. AP Barcelona Attack Injured people react after a van crashed into pedestrians in Las Ramblas, downtown Barcelona, Spain, 17 August 2017. According to initial reports a van crashed into a crowd in Barcelona's famous Placa Catalunya square at Las Ramblas area injuring several. Local media report the van driver ran away, metro and train stations were closed. The number of people injured and the reasons behind the incident are not yet known. Official sources have not confirmed that the incident is a terrorist attack. EPA Barcelona Attack People flee the scene in Barcelona, Spain, Thursday, Aug. 17, 2017 after a white van jumped the sidewalk in the historic Las Ramblas district, crashing into a summer crowd of residents and tourists and injuring several people, police said. (AP Photo/Giannis Papanikos) AP Barcelona Attack People are pictured inside Systemaction, a locked down store after a van crashed into crowds on Las Ramblas in Barcelona, Spain, August 17, 2017. Courtesy Abbie Yermus/Handout via REUTERS ATTENTION EDITORS - THIS IMAGE WAS PROVIDED BY A THIRD PARTY. REUTERS Barcelona Attack People take shelter inside a shop in Barcelona, Spain, Thursday, Aug. 17, 2017. A white van jumped up onto a sidewalk and sped down a pedestrian zone Thursday in Barcelona's historic Las Ramblas district, swerving from side to side as it plowed into tourists and residents. Police said 13 people were killed and more than 50 wounded in what they called a terror attack. (AP Photo/Manu Fernandez) AP Barcelona Attack People move from the scene after a van crashed into pedestrians near the Las Ramblas avenue Reuters Barcelona Attack A policeman stands next to an ambulance after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona AFP/Getty Images Barcelona Attack People are evacuated from a street after a van crashed into pedestrians near the Las Ramblas avenue in central Barcelona, Spain, August 17, 2017. REUTERS/Stringer NO RESALES. NO ARCHIVE. Reuters Barcelona Attack Firefighters stands outside an evacuated mall after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona AFP/Getty Images Barcelona Attack Policemen stand next to vehicles in a cordoned off area after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona AFP/Getty Images Barcelona Attack Plain-clothes policemen phone as they walk past police cars in a cordoned off area after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona AFP/Getty Images Barcelona Attack A policemen and a medical staff member stand past police cars and an ambulance in a cordoned off area after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona AFP/Getty Images Barcelona Attack A person is stretched out of a mall by medical staff members in a cordoned off area after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona on August 17, 2017. Police in Barcelona said they were dealing with a "terrorist attack" after a vehicle ploughed into a crowd of pedestrians on the city's famous Las Ramblas boulevard on August 17, 2017. Police were clearing the area after the incident, which has left a number of people injured. AFP/Getty Images Barcelona Attack Children, some in tears, are escorted down a road in Barcelona, Spain, Thursday, Aug. 17, 2017. Police in Barcelona say a white van has mounted a sidewalk, struck several people in the city's Las Ramblas district. AP Barcelona Attack Mossos d'Esquadra Police officers and emergency service workers move an injured man, after a van crashes into pedestrians in Las Ramblas, downtown Barcelona, Spain, 17 August 2017. According to initial reports a van crashed into a crowd in Barcelona's famous Placa Catalunya square at Las Ramblas area injuring several. Local media report the van driver ran away, metro and train stations were closed. The number of people injured and the reasons behind the incident are not yet known. Official sources have not confirmed that the incident is a terrorist attack. EPA Barcelona Attack Mossos d'Esquadra Police officers attend injured people after a van crashed into pedestrians in Las Ramblas, downtown Barcelona, Spain, 17 August 2017. According to initial reports a van crashed into a crowd in Barcelona's famous Placa Catalunya square at Las Ramblas area injuring several. Local media report the van driver ran away, metro and train stations were closed. The number of people injured and the reasons behind the incident are not yet known. Official sources have not confirmed that the incident is a terrorist attack. EPA Barcelona Attack Injured people react after a van crashed into pedestrians in Las Ramblas, downtown Barcelona, Spain, 17 August 2017. According to initial reports a van crashed into a crowd in Barcelona's famous Placa Catalunya square at Las Ramblas area injuring several. Local media report the van driver ran away, metro and train stations were closed. The number of people injured and the reasons behind the incident are not yet known. Official sources have not confirmed that the incident is a terrorist attack. EPA Barcelona Attack A police officer cordon off a street in Barcelona, Spain, Thursday, Aug. 17, 2017. Police in the northern Spanish city of Barcelona say a white van has jumped the sidewalk in the city's historic Las Ramblas district, injuring several people. AP Barcelona Attack TOPSHOT - Policemen check the area after towing away the van which ploughed into the crowd, killing at least 13 people and injuring around 100 others on the Rambla in Barcelona, on August 18, 2017. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least 13 people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack". The driver of a van that mowed into a packed street in Barcelona is still on the run, Spanish police said. / AFP PHOTO / Josep LAGOJOSEP LAGO/AFP/Getty Images AFP/Getty Images Barcelona Attack TOPSHOT - Armed policemen stand in a cordoned off area after a van ploughed into the crowd, injuring several persons on the Rambla in Barcelona on August 17, 2017. Police in Barcelona said they were dealing with a "terrorist attack" after a vehicle ploughed into a crowd of pedestrians on the city's famous Las Ramblas boulevard on August 17, 2017. Police were clearing the area after the incident, which has left a number of people injured. / AFP PHOTO / Josep LAGOJOSEP LAGO/AFP/Getty Images AFP/Getty Barcelona Attack A man displays flowers at the Canaletas fountain on the Rambla boulevard on August 18, 2017, a day after a van ploughed into the crowd, killing 13 persons and injuring over 100 on the Rambla in Barcelona. Drivers have ploughed on August 17, 2017 into pedestrians in two quick-succession, separate attacks in Barcelona and another popular Spanish seaside city, leaving 13 people dead and injuring more than 100 others. In the first incident, which was claimed by the Islamic State group, a white van sped into a street packed full of tourists in central Barcelona on Thursday afternoon, knocking people out of the way and killing 13 in a scene of chaos and horror. Some eight hours later in Cambrils, a city 120 kilometres south of Barcelona, an Audi A3 car rammed into pedestrians, injuring six civilians -- one of them critical -- and a police officer, authorities said. / AFP PHOTO / Josep LAGOJOSEP LAGO/AFP/Getty Images AFP/Getty Images Barcelona Attack TOPSHOT - The van who ploughed into the crowd, killing at least 13 people and injuring around 100 others is towed away from the Rambla in Barcelona on August 18, 2017. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least 13 people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack". The driver of a van that mowed into a packed street in Barcelona is still on the run, Spanish police said. / AFP PHOTO / Josep LAGOJOSEP LAGO/AFP/Getty Images AFP/Getty Barcelona Attack TOPSHOT - Forensic policemen arrive in the cordoned off area after a van ploughed into the crowd, killing 13 persons and injuring over 80 on the Rambla in Barcelona on August 17, 2017. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least 13 people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack". / AFP PHOTO / Josep LAGOJOSEP LAGO/AFP/Getty Images AFP/Getty Images Barcelona Attack TOPSHOT - A person is helped by Spanish policemen and two men after a van ploughed into the crowd, killing at least 13 people and injuring around 100 others on the Rambla in Barcelona on August 17, 2017. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least 13 people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack". The driver of a van that mowed into a packed street in Barcelona is still on the run, Spanish police said. / AFP PHOTO / Nicolas CARVALHO OCHOANICOLAS CARVALHO OCHOA/AFP/Getty Images AFP/Getty Images Barcelona Attack TOPSHOT - Policemen accompany clients of a store outside a cordoned off off area after a van ploughed into the crowd, killing 13 persons and injuring over 80 on the Rambla in Barcelona on August 17, 2017. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least 13 people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack". / AFP PHOTO / LLUIS GENELLUIS GENE/AFP/Getty Images AFP/Getty Images Barcelona Attack TOPSHOT - Forensic policemen arrive in the cordoned off area after a van ploughed into the crowd, killing at least 13 people and injuring around 100 others on the Rambla in Barcelona. A driver deliberately rammed a van into a crowd on Barcelona's most popular street on August 17, 2017 killing at least 13 people before fleeing to a nearby bar, police said. Officers in Spain's second-largest city said the ramming on Las Ramblas was a "terrorist attack". The driver of a van that mowed into a packed street in Barcelona is still on the run, Spanish police said. / AFP PHOTO / PAU BARRENAPAU BARRENA/AFP/Getty Images AFP/Getty Images