As the hunt intensifies for members of a Moroccan-led cell thought to be responsible for the terror attacks in Spain, attention has turned to the hundreds of returned jihadists across the Strait of Gibraltar who intelligence officials fear pose a large, residual threat on Europe’s doorstep.

Up to 1,000 jihadists are thought to have been smuggled back to Morocco and Tunisia from the battlefields of Islamic State’s now crumbling caliphate. About 300 are thought to have returned to Morocco, from where six of the 12 terrorists who carried out the attacks in Catalonia are believed to have hailed.

A former leading member of the extremist group’s external operations arm said the exodus of Isis fighters included militants who had fled disenfranchisement and lives of petty crime and felt aggrieved by their status in Europe – particularly France. With the land controlled by Isis shrinking by the week, he believes that some of them will take their grievances back to their countries of birth and use the proximity of Spain to launch attacks, or infiltrate further into the continent.

At the height of Isis’s powers, up to 1,600 Moroccans are believed to have travelled to Iraq and Syria, making them, per capita, one of the largest national groups in the fast-shrinking caliphate. Roughly half that number have since been killed. Long feared as a breeding ground for extremists, north Africa is now increasingly being seen as a launchpad for attacks on Europe to avenge Isis’s loss of land and personnel.

The former Isis leader, who abandoned his role in late 2015, said he had mentored six Moroccans who had left disadvantaged backgrounds in France and sought a sense of purpose under Isis rule. He also worked with others who had travelled directly from the north African country, all of whom were radicalised before they arrived.

“The homegrown ones had a severe approach,” he said in an interview. “The ones from France were upset at their lives. One told me he used to sell drugs, another was a thief.

“They were looking for something. And they deeply believed that they were not at home in France.”

A sense of class struggle in societies that they perceived as unwelcoming has been a frequent theme among men and boys who travel from north Africa to join Isis. Tunisian fighters are thought to have had the highest per capita representation among the extremist group’s foreign fighter ranks – up to 1,800 men and boys. Large numbers were deployed as suicide bombers in the Kobani offensive of late 2014 and the failed attempt to hold on to Mosul this summer.

The former Isis leader said that the jihadists “complained of discrimination, that they were not being treated fairly and never would be. One of them became a very good friend. When I left, he stayed. He was swept deeper into Isis.

“Spain wasn’t discussed, but France came up all the time.”

As the perceived utopia of the caliphate declared by Isis leader Abu Bakr al-Baghdadi in mid-2014 gave way to the reality of savage, relentless war and loss, Moroccan members of Isis started contacting their families, looking for ways to return.

They were looking for something. And they deeply believed that they were not at home in France

Several hundred are thought to have made it back across the Turkish border. Although most of them found a route home, up to 30 are understood to have been detained by Turkish authorities.

Some of the Moroccans fought in Iraq but the majority were sent to Syrian battlefields in the north, where thousands of men – mostly foreigners – died in a series of futile pushes, mainly against US-backed Kurdish groups.

“We would send hundreds of people out to be killed and they would all die,” the former leader said. “I would ask what happened to him, or him, and the answer would come back that he had been killed soon after he had left.

“There was a whole Turkish unit of more than 100 men who went to fight the Kurds. Only three of them came back.

“The Moroccans saw what the rest of us saw. They didn’t want to stay either. Only the hardcore ones did.”

Officials in Rabat say they have a strong understanding of citizens who left to fight and have since returned. An estimated 90 jihadists are thought to have been imprisoned after arriving from Iraq and Syria. However, several dozen more are believed to have melted back into towns and cities.

Within the ranks of those who originally fled were several dozen men who had been convicted of extremism and served jail time. “These guys usually got fake Libyan passports and made it to Turkey,” the former Isis leader said.

Moroccan authorities say they have prevented several large-scale terror attacks in Casablanca and Rabat but have limited means to stop their nationals conducting operations outside the country. Morocco’s proximity to Spain and the large expatriate population there had long been seen as worrying.