Olivier Guitta is the Managing Director of GlobalStrat, a security and geopolitical risk consulting firm for corporations and governments.

Last Thursday, the Foreign Office advised British citizens to leave Tunisia quickly because of a highly likely terror attack. After the attack that killed 39 people, including 30 Britons on a beach in the tourist resort in Sousse, Béji Caïd Essebsi, the country’s President, said he was surprised by the bloodiest terrorist attack in the history of his country. But it should definitely not have been a surprise. Since the 2011 Jasmine Revolution, Tunisia has had to face a huge security problem, and numerous red flags were raised in the past few months. How did it get so bad so quickly?

Tunisia has witnessed a huge increase of jihadi terrorism since the demise of Ben Ali, the former dictator, in 2011. Indeed, while there were two attacks between 2001 and 2011 – that included an Al Qaeda attack in Djerba in April 2002 that killed 19 including 14 German tourists – there have been 50 since 2013. While most of these post-revolution assaults targeted soldiers and various law enforcement individuals, one should not forget that Western targets were also hit – even before the Bardo museum attack that killed 23 in March.

These have varied from the assault on the US embassy and American school in Tunis in 2012 to the failed attack that resonates the most today in our minds: in 2013, a suicide bomber blew himself up on the beach in Sousse near the Riyadh Palms hotel, about five miles away from the beach where the recent slaughter took place. On that same day, five other people were arrested in Sousse on suspicion of planning similar attacks, and another suicide bomber was arrested in Monastir for targeting the Habib Bourguiba mausoleum.

In fact, the security problem that Tunisia has been confronted with since 2013 can be traced back to the ambiguous policies of the Muslim Brotherhood Ennahda party that held power in Tunisia from 2011 to 2013.  A poll conducted that year revealed that 65 per cent of Tunisians considered the terrorist threat to be high, and that 74 per cent blamed it on Ennahda’s lenient policy towards jihadists.

While publicly condemning violence, Ennahda was repeatedly accused of failing to act against the Salafists that have grown to about 50,000 in number, according to the International Crisis Group. In 2012, a leaked video of Rashid Ghannouchi, Ennahda’s leader (who ironically spent 20 years living in London in exile) showed him talking to Salafists and explaining that he wanted to set up an Islamic republic in which laws would be inspired by the Shariah – a goal that Al Qaeda in the Islamic Maghreb (AQIM) had acknowledged earlier that they had in common with Ennahda- a nd secularism would be wiped out. He went on to request that the Salafists continue a proselyting campaign in the mosques and within society which, combined with Ennahda’s action in government, would be very effective.

The main jihadist outfit in the country until last year was Ansar al Shariah (AST), a loose offshoot of AQIM, which allegedly recruited the perpetrator of the Sousse massacre, Seif Rezgui, before he defected to the Islamic State.

Abu Iyadh, its leader, was previously the co-head of the Tunisian Combating Group in Afghanistan, which was behind the murder of Commandant Massoud on in 2001. He was freed by the new authorities after the revolution in 2011, part of the general amnesty that freed other Salafi-jihadists. He was allegedly killed during a US drone strike in Libya in 2015. That group can be blamed for most of the attacks in Tunisia before 2015, including the brutal murder in 2013 of two anti-Ennahda political figures – first, Chokri Belaid, who had the night before his assassination accused Ennahda of giving ‘an official green light’ to political violence and then Mohamed Brahmi. Only under huge pressure from the public did Ennahda finally ban AST in August 2013.

While it is true that external elements – such as the spillover of Islamist fighters from Mali after the French intervention in 2013, and the Libyan jihadi theatre failed state next door with its almost unlimited access to weapons – have been contributing to the rise of terrorism, one cannot discount the rise of homegrown Salafi-jihadist extremism. It is very worrisome that Tunisia provides today the largest contingent of jihadists in Syria/Iraq, numbered at about 4,200 and also maybe up to 1,500 in Libya.

But what’s even more concerning in terms of numbers is that authorities have prevented another 15,000 from going – in a country of about 10 million. Knowing the huge draw of jihad in foreign lands, Abu Iyadh, AST’s leader, has called for his followers to stay in Tunisia and fight the jihad at home. A call relayed by AQIM is that it does not want to “leave Tunisia in the hands of the seculars”.

Even though the local Islamic State branch in Tunisia appeared just a few months ago, the group has already been able to pull off the two bloodiest terror attacks in the country’s history – and, furthermore, against Westerners. Its goal to cripple the Tunisian economy and, in particular, the vital tourism sector may be reachable now, since one can expect an even larger drop of Western tourists than after the Bardo attack. Coincidentally Salafists said as early as 2013 that they wanted to stop the flow of non-Muslim tourists altogether in Tunisia and replace them with Muslim visitors.

ISIS would like to see Tunisia’s democratic model fail to make sure more people are convinced about the superiority of the Caliphate. The West should not let that happen, and realise that the battle for Tunisia’s both hearts and minds is really the same that it has to combat at home when it comes to Islamist extremism. Tunisia deserves this, the victims of the terror attacks deserve this, and we deserve this.