Country has been on its second highest alert since 2015, and Catalonia has a reputation as a meeting place for radicals

Images of the aftermath of the attack on Barcelona’s most famous street on Thursday will stir different images in the minds of different people. For those in France and the UK, they will be reminders of the attacks on the Promenade des Anglais in Nice and on Westminster Bridge in London.

For many Spaniards, they will bring back memories of 11 March 2004, when 191 people were killed and more than 1,800 others injured in a series of train bombings in Madrid carried out by al-Qaida.

Older Spaniards will also remember Eta’s violent struggle for Basque independence, a failed campaign that killed more than 800 people in bombings and shootings over a period of decades.

But if the spectre of Eta has faded six years after the group began giving up its weapons – and 20 years after its murder of a young politician marked a turning point in Spanish society – the same cannot be said of the threat of Islamist terrorism.

Thirteen years may have passed since the Madrid bombings, but Spain’s counter-terror specialists remain engaged in a daily battle to thwart attacks and identify those planning them.

The country has been on its second highest terror alert since June 2015, and barely a week goes by without police announcing the arrests of people who have become radicalised online.

More than 720 people have been detained in Spain in connection with “jihadi terrorism” since the carnage in Madrid, and almost a quarter of the 178 people arrested for terrorism-related activities over the past three years are from Barcelona.

A recent study from West Point’s Combating Terrorism Center found the main nationalities of those arrested were Moroccan (42.7%) and Spanish (41.5%).

Although most are thought to have been radicalised by the war in Syria, some jihadis find Spain a peculiarly atavistic target because of the country’s 700-year period of Moorish occupation. Islamic State was quick to look to the past and claim credit for the Barcelona attack, trumpeting: “Terror is filling the crusaders’ hearts in the Land of Andalusia.”

The subsequent attack in Cambrils in the early hours of Friday was not the first time this quiet beach town has become mixed up in international terrorism. Cambrils was a meeting place for plotters who prepared the 9/11 attacks in New York and Washington; the plot’s mastermind, Mohammed Atta, met one of his key aides there in the weeks before the Twin Towers were brought down.

Ramzi Bin al-Shibh, who was originally meant to be one of the pilots of the aircraft that were taken over by the 9/11 attackers, was staying at the Hotel Cristina in Cambrils when Atta visited him in July 2001. Atta stayed at a hotel in nearby Salou.

Although Bin al-Shib, who was later arrested, denied having met anyone else during their brief trip to Spain, the eastern region of Catalonia has long had a reputation as a meeting place for Islamist radicals.

The attacks in Barcelona and Cambrils, together with the explosion at what appears to have been a makeshift bomb factory further south, in Alcanar, on Wednesday night, suggest Catalonia remains a significant operational and recruiting base.

The response to the latest attacks from Spain’s prime minister – who said “jihadi terrorism” would not tear apart a united country – may not sound surprising, but Spain is far from united at the moment.

The Catalan regional’s government’s decision to hold a referendum on seceding from Spain on 1 October has left relations between Madrid and Barcelona at their lowest point in three years.

Rajoy will be mindful of the electoral disaster that engulfed his ruling conservative People’s party (PP) after the Madrid attacks. His predecessor, José María Aznar, initially insisted that the bombings – three days before the 2004 general election – were the work of Eta rather than Islamist terrorists. The Spanish people punished the PP by voting the Socialist party into power.

But both Rajoy and the Catalan president, Carles Puigdemont, will know that there is far more than politics at stake here. All of Spain’s citizens must be kept safe and its vital tourist economy protected, and the country will also be keen to maintain its reputation as a welcoming place for the huge numbers of migrants who helped drive the pre-crash economic boom.

Unlike most European countries, Spain has not seen the emergence of a large-scale, far-right party that seeks to exploit anxieties about immigration and Islam.

The Catalan chant that rang around Barcelona’s main square after the minute’s silence on Friday lunchtime hinted at residents’ resolve. “No tinc por”, they shouted – “I am not afraid”.

Or, as Puigdemont put it a little later: “We are determined to win against terrorism with the best weapon that our society has and that is solidarity, freedom, respect.”