The recent bloodthirsty raid by jihadist militants from the Islamic State group (IS) in northern Mozambique has shocked the world.
Hundreds of well-armed fighters were able to overrun a town close to Africa's largest gas project. They massacred dozens of people, locals and expatriates, leaving decapitated bodies strewn around the streets.
So how was this able to happen, why can the Mozambican government not control this insurgency and what will it take to defeat it?
Who are the insurgents?
They call themselves al-Shabab, an Arabic word for "the young men" or "the lads". This is misleading as they are not the same group as Somalia's al Qaeda-linked insurgents who also go by that name. Instead, this group pledged allegiance in 2019 to the rival IS group, based in Iraq and Syria. They have adopted the title of Islamic State Central Africa Province (ISCAP), which again is misleading since Mozambique is not part of Central Africa.
In a pattern that has repeated itself elsewhere in the world, such as in Mali, Iraq and Nigeria, this insurgency grew out of local people's grievances at feeling marginalised and discriminated against by their own government.
Mozambique's Cabo Delgado province, where they operate, is more than 1,600 km (990 miles) away from the capital Maputo but it contains the largest and richest Liquid Natural Gas (LNG) project in Africa. Operated by the French company Total, it is estimated to be worth US$60bn (£44bn) with investment from countries including the UK.
Local residents complain they have seen little of this wealth or investment passing down into their community which prompted the beginnings of the insurgency in 2017, later becoming "internationalised" as they gained support from IS.
Scruffily dressed and with no definable uniform, the jihadists who overran the town of Palma last weekend were nevertheless well-armed with assault rifles and rocket-propelled grenades. From the videos later posted online by IS, their one unifying feature appears to be the red bandanas that many wore around their foreheads to denote a significant raid.
They were also sufficiently well-motivated and led to have launched a successful multi-pronged attack that quickly overcame the ineffective security provided by the Mozambican government.
"Even though it is a local jihadist insurgency," says Olivier Guitta, a geopolitical risk analyst with GlobalStrat and expert on jihad in Africa, "al-Shabab has established links to Islamist militias in East Africa. Radical spiritual leaders there have assisted with the religious and even military training of youths in northern Mozambique."
So this insurgency is essentially a local one that has opportunistically cloaked itself in the banner of IS and then attracted world attention through its graphic violence and by its proximity to such an important commercial project.
What will it take to defeat them?
A great deal more effort than has been made so far is the answer.
Recognising it had a serious problem, Mozambique's government hired more than 200 military "advisers" from the formidable Russian private military contractors, the Wagner Group, in September 2020.
These mostly ex-Russian Special Forces soldiers have operated with a nod of approval from the Kremlin in Syria, Libya and elsewhere. They brought with them drones and data analytics but, as Olivier Guitta points out, things did not turn out as they had expected.
"After suffering a series of ambushes and nearly a dozen reported deaths in several battles in densely forested districts of Cabo Delgado, the Russian private military contractors have gone into a strategic retreat."
The most immediate problem is the weakness of Mozambique's own security forces and perhaps a misplaced complacency on the part of its political leaders.
Brigadier Ben Barry from the International Institute for Strategic Studies (IISS) says IS militants have a proven ability in fighting in built-up areas that is proving a challenge for Mozambique and its partners.
"Success in urban warfare requires government forces to have high standards of leadership and training in urban tactics. These factors may explain the apparent weakness of Mozambique forces. They seem to lack the support of Western military advisers and the ability to use air power, precision weapons and armoured vehicles, all essential for the eviction of IS forces from Iraqi and Syrian towns and cities."
In recent days the Pentagon has sent a small detachment of Green Beret Special Forces trainers to bolster the efforts of Mozambique's military and Portugal, the former colonial power, has also pledged a small number of army trainers. France is reportedly monitoring the situation from its nearby island of Mayotte and South Africa is taking a close interest in its neighbour. However, any major military involvement by Western powers carries its own risks.
"As we have seen elsewhere in northwest Africa," says Benjamin Petrini, a research fellow at IISS, "a large foreign military presence may further exacerbate the conflict politically and the instability."
But he adds that "the role of South Africa [whose private military contractors rescued many of the trapped workers from the recent raid] as a regional peace enforcer may also be considered".
IS tactics are typically brutal and horrific. Unlike al-Qaeda which, while still murderous in its actions, often makes some effort to build local support, these insurgents have carried out bloodthirsty raids on local communities, indiscriminately slaughtering and beheading civilians. In one raid this year not even an 11-year-old boy was spared being killed in front of his mother.
In the short term this establishes a fearsome reputation, with perhaps an exaggerated cloak of invincibility. But in the longer term few insurgencies can progress without local support. Al-Qaeda in Iraq made the mistake of so terrorising the local Sunni Muslim population in Anbar province in 2007 - such as cutting off men's fingers for the simple offence of smoking a cigarette - that the US-led Coalition there was able to persuade local tribes to rise up against al-Qaeda in what became known as "the Awakening".
In Mozambique it may well take something similar. Counter-insurgency is never just about military victories, it involves that old cliché of "winning hearts and minds". So to defeat this insurgency, yes, it will initially take a properly equipped and co-ordinated campaign by Mozambique's own forces, with foreign logistic assistance. But for it to succeed in the long term it will take far more than that.
It needs good governance and investment in the local community: schools, roads, jobs - enough to assuage people's sense that they have been abandoned by their government while big foreign multinationals sweep in and reap the benefits of their country's precious natural resources.
In Afghanistan I saw how tactical military victories over the Taliban by Nato and Afghan government forces were later undone by a failure of government. Areas "liberated" from Taliban rule later slipped back under their sway once the troops departed and corrupt police and government officials resumed their nefarious activities at the expense of the local population.
The same will happen in Mozambique if the coming military effort is not backed up by a marked improvement in civil affairs.
Mozambique's jihadists appear to be aiming to create their own self-declared "caliphate" in Cabo Delgado province, just as IS did in Mosul back in 2014.
The possibility that they could ever succeed in gaining control over a $60bn gas project is almost unthinkable.
While it is hard to see how they would ever be able to manage and export from it by conventional means it could still give them enormous economic power, funding future operations and perhaps funnelling money back to IS central in Iraq and Syria.
It took five years and a horrendous toll in lives for a coalition of 83 nations to finally defeat the last of the IS "caliphate" in Syria. When it was over, world leaders said IS must never again be allowed to build such a caliphate.
If Mozambique's insurgency is not defeated then that promise will be put to the test.