MADRID — The investigation of attacks that killed 16 people in Barcelona and a nearby town is becoming increasingly international, as police piece together who ordered the carnage and how. The clues include a lightning-fast shopping trip to a Paris suburb and plane tickets to Belgium.

At the center of the probe is a mysterious imam, Abdelbaki Es Satty, who went from trafficking people and drugs to secretly preaching jihad to young Muslims in northeastern Spain.

He was never directly linked to extremism or recruiting, but he appeared on authorities’ radar more than once, spending nine months in an anti-radicalization program in prison. A short time after being released, he managed to pull together a tightly knit group of as many as nine men — three sets of brothers and their childhood friends, all willing to die for his cause and keep the plot secret.

In addition to the 16 dead, more than 120 people were injured in the attacks, which were claimed by the Islamic State group. Spanish authorities say the cell has been fully dismantled, its members dead or under arrest, but they are still working to piece together how exactly the attacks coalesced.

“It wasn’t an attack planned by the central command of Daesh,” Spanish Interior Minister Juan Ignacio Zoido recently said, using another name for the IS group in an interview with the ABC newspaper. “But it has been guided from overseas.”

A Spanish official speaking on condition of anonymity because he was not allowed to discuss the ongoing probe told The Associated Press the Spanish cell communicated only face-to-face, never online, even in encrypted programs such as Telegram.

The weekend before the attacks, several of them made the nine-hour drive to the Paris suburb of Malakoff for an overnight stay. They bought a camera before leaving again in an Audi A3. Investigators in both countries are focusing on what the group needed in France that they couldn’t learn online, from each other — or their imam.

Four days after their return, on Aug. 16, Es Satty himself made a fatal mistake in his bomb-making workshop, frustrating the group’s initial plan to strike Barcelona’s tourism and religious monuments.

The attacks were carried out the following day by Es Satty’s recruits, aged 17 to 28. One rammed a van into Barcelona’s busy Las Ramblas boulevard. Hours later five of them armed with knives, an axe and fake explosive belts drove the Audi onto a beach promenade in Cambrils, south along the Mediterranean coast from Barcelona.

A real explosives belt, complete with a detonator, was found along with Es Satty’s remains. A survivor of the blast said the imam planned to blow himself up and take as many victims as possible with him. Near his battered wallet were discount airline tickets to Belgium. It wasn’t clear what he planned to do next.

Es Satty’s first run-in with authorities in Spain dates to 2002, when he was arrested in the northern Africa enclave of Ceuta for using a forged passport to smuggle in a fellow Moroccan. The judge gave him a six-month suspended prison sentence. Because he stayed out of trouble for at least two years, he avoided prison.

He had moved in with an older relative named Mustapha who lived in central Vilanova i la Geltru, a coastal town 50 kilometers (30 miles) south of Barcelona where he started preaching. But his name resurfaced as part of two separate investigations linked to the 2004 al-Qaida bombings of Madrid commuter trains.

A photocopy of his ID was found along with documents of 17 other people in the home of a Moroccan-born businessman accused of providing shelter and logistical help to Islamic extremists, according to court documents obtained by the AP. Both Es Sattys came under investigation, and the imam’s cellphone was tapped for at least a month in a related probe into document forgery.

Zoido said last week that judicial police and the investigating judge “never found any sign that pointed at the radicalization of (Abdelbaki) Es Satty.” Mustapha was acquitted, and Spain’s top court threw out sentences against the rest of the cell, ruling that the wiretapping was illegal, evidence was inconclusive, and some confessions were extracted under duress.

By then, the imam had moved to Calafell, south of Vilanova. On his 37th birthday in 2009, a drug-sniffing dog found 121 kilograms (266 pounds) of hashish in his car as he was about to board a ferry. He was sentenced to four years in prison and fined 176,000 euros ($210,000), the market value of the drugs.

While jailed in the same prison as one of the Madrid train bombers, Es Satty took part in a program for inmates “vulnerable for recruitment or radicalization,” Spain’s Interior Ministry told the AP. After less than a year, he was removed from the program and allowed brief furloughs for good behavior. In 2015, skirting an expulsion order for the drug conviction, he was freed for good and made his way to Ripoll, at the time a town in need of an imam. His wife and children remained in Morocco.

By then, Es Satty had apparently learned what he needed to start up his own cell, impervious to infiltration.

According to a relative of one of the attackers, Es Satty jumped from home to home for Friday dinners, taking advantage of his status as a bachelor and the hospitality of his congregation to get to know families better. The relative spoke on condition of anonymity, fearing retaliation.

At some point in late 2015, the town’s Muslim community had split into two congregations and Es Satty lost his job. He disappeared to Belgium, looking for work as an imam in Vilvoorde, a town south of Brussels that — at the time — was losing young men to the war zone in Iraq and Syria.

Without using Europol channels to exchange country-to-country information, police agents in Belgium and Catalonia exchanged emails about Es Satty, officials in both countries have acknowledged.

But the Catalan regional police replied saying the imam was free of any suspicion, failing to pass on information relating to past offences that was only in the hands of the central government in Madrid.

The lack of coordination at regional, national and European levels has been at the center of the post-attacks blame game in Spain, as all sides look for political gains ahead of a controversial vote on Catalonia’s independence.

But for Es Satty, back in March 2016, the clogged information flow provided an opportunity to leave Vilvoorde, unnoticed, as soon as a criminal records certificate was requested.

Soon after he returned to Ripoll, he went to work at the new mosque, an unmarked storefront near the train station and within walking distance of his flat in the city center.

Another relative of two of the attackers told AP that he preached about jihad and killing infidels often enough to make her uncomfortable, but she didn’t dare speak out at the time. She also spoke on condition of anonymity because she feared retaliation.

He lasted less than a year before leaving the job in June.

By then, he had gathered around him three sets of brothers, including the siblings whose Audi A3 was seen coming and going from the house in Alcanar where Es Satty would ultimately die.

That same Audi was caught speeding on the highway in France the weekend before the attack. Its occupants, a few of the young men from the cell, drove to the southern suburb of Malakoff and used a bank card to buy a camera, French officials say.

Neither they nor Spanish officials believe that the men undertook the nine-hour drive for a simple shopping expedition, nor do they believe that Malakoff was chosen at random. Zoido, Spain’s interior minister, said the probe into the international links have opened new investigative strands into the attacks in Barcelona and Cambrils, “but also into other events that could be related.”

Malakoff has a history of jihadi ties, dating to January 2015 when an IS extremist shot a policewoman to death there before attacking a kosher supermarket later the same week. In November 2015, a surviving member of the IS cell that attacked Paris trekked across the city to a metro station less than 2 kilometers (1 mile) away, ditching a fake suicide belt and calling on friends to come pick him up.

Lori Hinnant reported from Paris.