At 10:50 on Thursday 27 June, a suicide bomber attacked a police patrol in downtown Tunis. One officer was killed, while another officer and a bystander were injured. Less than 30 minutes later, 1.5 km away, another bomber attacked a counter-terrorism unit leaving their barracks to investigate the first blast. The explosion injured six officers, two critically. The Islamic State claimed responsibility for both attacks.
The bombings, coming a day after the fourth anniversary of the terrorist attack on foreign tourists in Sousse where 38 died, underscore the ongoing complexity of Tunisia's security challenges.
The state needs to avoid the temptation of doubling down and focusing on technical policing alone to combat terrorism. Instead, the whole of government should be mobilised to improve social, economic, governance and ideological conditions that drive radicalisation and threaten Tunisia's stability.
Tunisia faces two distinct security challenges. The first involves small cells of individuals who staged recurrent low-level attacks in urban areas over the past few years, including a suicide bombing in Tunis last October and poisoned letters earlier this year. Nearly all have targeted government personnel, especially members of the security forces. None have caused significant casualties.
Preventing terrorism hasn't commanded the resources or interest lavished on training security forces
The decline in violence in Tunisia's cities is attributable to the growing technical skill and experience of the security forces, and their ability to identify and arrest terrorists before they strike. However, as government has become more capable in tracking terrorists, the job has become more difficult.
Many of the terrorist cells have claimed allegiance to Islamic State. But the connections seem limited, with little indication that they've received active training or operational support from the global terrorist network. Rather their operational skills are self-taught, often amateurish and prone to failure. However, because of their limited visibility, security forces struggle to identify and interdict such groups.
The synchronisation of Thursday's attacks and the targeting of first responders is atypical in Tunisia. It is a worrisome sign that urban terrorist cells may be becoming better organised and more strategically capable, even as they evade security force attention.
The second security challenge is in Tunisia's rugged north-west. Two terrorist groups, one affiliated with al-Qaeda in the Islamic Maghreb and the other with Islamic State, have waged a low-grade insurgency since 2011. As in the cities, mainly security and military personnel have been targeted, killing nearly 150 and wounding over 200 over the past eight years. Tunisian civilians have also increasingly been attacked, seemingly in an attempt to terrorise them into acquiescence.
The government has notched some significant successes in the north-west, killing many terrorists and significantly lowering the number of attacks. However security forces haven't been able to end the fighting. Instead, the Islamic State affiliate seems to be expanding its zone of operations southward, reoccupying territory that the government retook from al-Qaeda years ago.
The synchronisation of Thursday's attacks and the targeting of first responders is atypical in Tunisia
Assessments of terrorism in Tunisia's urban and rural areas tend to focus on the international linkages. Al-Qaeda has concentrated on Tunisia for nearly two decades, with Algerian and Sahelien fighters active in the western mountains. Likewise, many Tunisians joined the Islamic State in Syria, and a growing number of Tunisian foreign fighters have come home.
But focusing on the international connections obscures the degree to which terrorism in Tunisia is driven by local factors and aimed at local targets. Tunisia's economic troubles continue to mount, degrading the quality of life of many middle- and working-class families.
Politicians have not delivered effective change or improved service delivery. This drives cynicism and disillusionment with democracy. More insidiously, deep structural inequality blocks access to economic opportunities and leads to the poor treatment by government officials (including security force officers) of those hailing from specific regions, neighbourhoods or families.
This has bred frustration among the youth. Some Tunisians have responded by migrating and others by engaging in cyclical social unrest. But some youth, particularly those from marginalised regions, neighbourhoods or families, have been radicalised by this frustration and have turned to terrorism, striking out at those they believe are responsible for their discontent.
This local focus can be seen in attack patterns in urban and rural areas. Attacks on foreign tourists are high profile but uncommon, as are incidents targeting Tunisian civilians. Most violence is aimed at government officials, mainly security and military personnel - as occurred in Thursday's bombings.
Better trained and equipped security forces can only minimise the threat, not beat it
The local drivers and persistent nature of terrorism in Tunisia underscore that attacks won't be stopped by security forces alone. Since 2015, the government, supported by international partners, has invested heavily in strengthening the ability of counter-terrorism forces and non-specialised police to uncover and respond to terrorism.
But better trained and equipped security forces can only minimise the threat, not beat it. Doing so requires addressing the country's economic malaise, underperforming political system and entrenched inequality - the conditions that fuel societal grievances and influence some youth to join terrorist groups.
While a number of initiatives to prevent extremism have been undertaken by government and international donors, many have been uncoordinated, with limited geographic reach and impact. Preventing terrorism hasn't commanded the financial resources or sustained government interest lavished on security force capacity building.
As the Tunisian government and international partners plan their responses to Thursday's attacks, investigations and prosecutions should be a priority. But those taking action must not lose sight of what drives terrorism in Tunisia. Security-first approaches must be expanded to include holistic strategies that prevent terrorist recruitment.
This means tackling the underlying problems that threaten Tunisia's stability. None of this can be done quickly or easily, and will require considerable strategic patience by security forces who have historically dominated government decision making on safety issues. It is however the best option to ensure that attacks don't continue to flare.
Dr Matt Herbert, Senior Research Consultant, ISS