By Mary Harper
Africa editor, BBC World Service News
In an audacious appointment, Somalia's new government has included a former al-Shabab militant, who once fought against the authorities, in the cabinet, but the weekend's deadly hotel siege is a reminder of the tough task ahead for those in power.
When Somalia's new President Hassan Sheikh Mohamud took office in May he declared a top priority was bringing an end to the country's 15-year Islamist insurgency.
Three months later al-Shabab staged one of its most spectacular ever attacks, storming a hotel a short drive away from the presidential palace in the capital, Mogadishu.
They held it for 30 hours. Officials said more than 20 people died in the siege of the Hayat and 117 were injured.
Less than a month earlier, the group mounted an unprecedented invasion of neighbouring Ethiopia.
It was as if they were cocking a snook at the new president.
International diplomats have described the complex, coordinated attack as a "game-changer" that took at least 18 months to plan and involved an estimated 1,200 fighters.
The then-commander of US Africa Command, General Stephen Townsend, said the militants penetrated 150km (93 miles) inside Ethiopia.
One reason why the group was able to stage this brazen assault was the increase in conflict in Ethiopia after years of general stability and growth.
Shortly after civil war erupted in the northern Tigray region in November 2020, a member of al-Shabab called me up.
"We are simply crossing our arms and enjoying the spectacle of Ethiopia destroying itself," he gloated. "The time to strike our primary enemy is finally approaching."
Ethiopia is one of the countries in the region which has sent troops to Somalia to support the government.
This is the second time President Mohamud has been in power. When I interviewed him shortly after the start of his first term in 2012, he said he would defeat the militants within two years.
Ten years later, they are still going strong.
The chairman of the Mogadishu-based Hiraal security think-tank, Mohamed Mubarak, says they are "more powerful and sophisticated than they were in 2012".
Al-Shabab has developed a parallel government and controls large swathes of territory.
It taxes people inside and outside areas it controls. Even Mogadishu residents prefer to use its justice system, which they consider more efficient and less corrupt than official courts.
The group continues to attack at will, firing mortars at parliament and into the heavily fortified international airport which houses embassies, the UN and foreign troops.
No wonder al-Shabab has been described as al-Qaeda's most successful affiliate.
President Mohamud acknowledges that al-Shabab cannot be defeated by brute force alone.
On 2 August, the government took the bold gamble of bringing in one of its former arch-enemies as part of a new strategy to end the conflict.
I was in Mogadishu at the time, in a car with friends stuck at a roadblock.
For once, nobody was in the least bit bothered about being ordered out of the car, bodies searched, vehicle and bags gone through with a fine-tooth comb.
As we waited in the only small patch of shade we could find, we went into a kind of trance, eyes glued to our mobile phones as we watched the prime minister's spokesman announce the new cabinet.
The name we were waiting for was that of a founding member of al-Shabab, trained in Afghanistan.
The rumours turned out to be true.
Al-Shabab's former deputy leader and spokesman, Mukhtar Robow, was named religious affairs minister.
While some were horrified by the move, many Somalis have greeted with enthusiasm the entry into government of a man who used to be on the US list of most-wanted terrorists with a $5m (£4.2m) bounty on his head.
They include the MP and former BBC correspondent Moalimuu Mohamed who bears the scars of being caught up in five al-Shabab attacks. A targeted suicide bombing earlier this year left him fighting for his life.
"I welcome Mr Robow's appointment," says Mr Mohamed.
"As a former jihadist leader he will contribute a lot to the fight against al-Shabab. He can work with the religious community to challenge extremist ideology and convince the militants that their beliefs do not follow the true path of Islam."
Mr Robow fell out with al-Shabab in 2013. He publicly denounced the group, even donating blood for victims of a huge truck bombing in Mogadishu in October 2017 which killed nearly 600 people.
He was detained in December 2018 and kept under house arrest until he was named as a government minister. He said he received the phone call while in detention.
The security expert, Mr Mubarak, describes Mr Robow's appointment as a "brilliant idea from a counter-terrorism perspective".
"He is a powerful tool, especially in terms of ideology, as he will provide strong doctrinal pushback against al-Shabab. As a founding member of the group he knows them inside out. He knows how they think and how they act."
Others have reacted with horror to Mr Robow's appointment and see it as yet another sign of the impunity that has marked Somalia's more than three decades of conflict.
Social media has been ablaze with criticism. Many of the remarks on Twitter were hostile:
"If Somalia was a working society, Robow would have been executed publicly."
"The appointment of this ruthless and vicious killer means only one thing: Al-Shabab has officially infiltrated Somalia's government."
Al-Shabab believes its former deputy leader's acceptance of a government job is a heinous crime, meriting the ultimate punishment.
In a 10-minute recorded statement the group's spokesman, Ali Dheere, said "Robow is an apostate. Shedding his blood is permissible."
President Mohamud believes his appointment combined with a renewed military offensive will weaken al-Shabab sufficiently to force it into talks.
"It all depends on political will," says Mr Mubarak.
"The downfall of al-Shabab will only come if the African Union and other foreign forces, federal and regional troops, and local militias all come together. Only then will they negotiate and make compromises."
Militant-turned-minister Mr Robow now talks of peace and forgiveness. He says he will work with Islamic scholars to persuade people to leave al-Shabab by convincing them that what they do is un-Islamic.
But it is unclear whether the government's gamble will pay off, or simply strengthen al-Shabab's resolve to fight harder than ever before.
Recent events suggest it will be the latter.
Somalia hotel siege ends leaving more than 20 dead
Militants 'raise more cash than Somali government'
Who are Somalia's al-Shabab?
A quick guide to Somalia
Russian strike on rail station kills 25 – Ukraine
UK ex-envoy to Myanmar arrested 'on visa offence'
French anger at UK sewage dumped in sea
‘Kill us, but don’t deport us to Myanmar’
On call with Italy's horseback doctor. Video
Is Biden's student debt forgiveness fair?
Why African countries are buying Turkish drones
People in Kyiv on the shock of six months of war. Video
Why India made a U-turn on free trade deals
Why Auckland is the 'spongiest' city
The workplace stigma that won’t budge
The war is static, but ousting Russia is a seismic task
Turkey's massive subterranean city
The language with no known origin
Why overthinkers struggle with remote work
© 2022 BBC. The BBC is not responsible for the content of external sites. Read about our approach to external linking.
By Mary Harper