As foreign troops withdraw from Somalia, could al-Shabab take over?
AFP via Getty ImagesSomalia is facing a fresh test of its stability as foreign troops begin withdrawing, funding for its security forces comes under pressure and a bitter political dispute threatens to derail plans for the country's first direct democratic elections in decades.
The combination of challenges has raised questions about whether the government can defend itself against Islamist militant group al-Shabab while managing growing divisions among political factions.
Some analysts fear the situation could embolden al-Shabab, which is affiliated with al-Qaeda, and potentially allow it to seize control of the capital, Mogadishu.
The group already controls large parts of the country despite the presence of about 12,000 African Union (AU) military personnel supporting the government.
The withdrawal of foreign forces, alongside the activities of clan-based militias aligned with rival political factions, has heightened concerns about the government's ability to maintain control.
Ugandan troops, who make up the largest contingent of the AU force, began withdrawing last month, with the country expected to complete its withdrawal by next year.
Ethiopia, another major contributor to the AU mission with over 7,000 soldiers, is also reportedly planning to withdraw almost half of its contingent.
The US, which had earlier announced cuts to funding for the UN Support Office in Somalia (Uunsos) has since said it is extending it for a year. Washington contributes about a quarter of the annual budget of about $500m (£380) of Unsos, which supports Somali security forces, AU missions and individual troop-contributing nations.
With military support uncertain and the government facing mounting political challenges, analysts question whether Somalia's security forces are ready to stand on their own.
The concerns were heightened recently when al-Shabab claimed to have killed hundreds of elite Somali soldiers in an attack. The government acknowledged the attack but did not disclose the number of casualties.
Abdisalam Guleid, a former deputy director of Somalia's National Security Agency, tells the BBC the security situation is increasingly precarious.
He warns that the withdrawal of foreign troops could leave Mogadishu vulnerable to a takeover similar to that of Afghanistan by the Taliban in 2021, following the withdrawal of US and Nato forces.
"I don't think Mogadishu will be able to defend itself. The Taliban-style [takeover]… that's the most likely scenario I can envision now," he says.
Such a scenario has played out in Somalia in the past, Guleid explains.
AFP via Getty ImagesIn the early 1990s, clan-based rebel groups advanced on Mogadishu from several fronts, forcing then-President Mohamed Siad Barre from power.
His overthrow triggered a devastating civil war and a prolonged humanitarian crisis. The collapse of state institutions subsequently created conditions in which Islamist militant groups, including al-Shabab, were able to expand their influence.
Guleid says Ugandan troops have been central to preventing a similar collapse since their first deployment to Somalia in 2007.
They played a key role in driving al-Shabab out of Mogadishu and other major towns, while protecting strategic installations, including the airport, port, government institutions and diplomatic missions.
Troops from Burundi, Djibouti, Kenya, Sierra Leone and Ethiopia later joined the AU mission, while countries including Turkey and the US maintained separate military deployments and provided training and equipment to Somali forces.
But Guleid argues that years of international assistance have not translated into the Somali government becoming militarily independent.
He says the authorities have become so reliant on foreign protection that they have neglected to adequately prepare their own forces to take over.
Somalia's Information Minister Abdifatah Qasim Mohamud rejects suggestions that the country would be unable to cope with the withdrawals.
He tells the BBC that Somali troops had already taken over some positions vacated by Ugandan forces and were prepared to assume greater responsibility for the country's security.
He says Somalia cannot depend indefinitely on foreign troops for its protection.
"I believe there is no reason for concern over this issue. There will be no change in the country's security situation or in the areas they have vacated," he says.
President Hassan Sheikh Mohamud has also been seeking continued international backing.
During a visit to Uganda on 23 November, he and President Yoweri Museveni called on the international community to continue supporting Somalia.
Getty ImagesNot everyone believes the withdrawal will necessarily result in a security collapse.
Ugandan security analyst Freddie David Egesa argues that years of international military support have helped Somalia establish the institutions needed to take greater responsibility for its security.
He says the withdrawal would provide an opportunity to assess how much progress has been made.
It would also force Somalia's political leaders to put aside their differences and take greater responsibility for the country's future, he added.
But other analysts warn that the timing could hardly be worse.
Omar Mahmood, an analyst at the International Crisis Group, says Somali forces are under considerable pressure as they fight al-Shabab while attempting to take over positions previously held by foreign troops.
This is a major undertaking for an army that was still developing, he says.
The military is also facing pressure in the Bay region of the South-West state, where forces loyal to ousted regional President Abdiaziz Hassan Mohamed have been fighting the federal government.
The withdrawal of Ugandan troops from the Lower Shabelle region could create further security challenges, Mahmood adds.
Mahmood further points to the long-delayed elections, which need to be secured, as another issue compounding the security situation.
Beyond the military situation, Mahmood says the government must also resolve a growing political dispute over the timing and format of the country's elections.
Somalia has been attempting to move away from an indirect electoral system in which clan elders select lawmakers, who then elect the president, towards a system of direct voting.
But the proposed changes have divided the government and opposition, with disagreements over how the elections should be conducted.
The dispute escalated this year after the president pushed through constitutional amendments extending the presidential term from four to five years, effectively delaying the next elections until 2027.
Anadolu via Getty ImagesThis month, the Supreme Court ruled against the extension, ordering political leaders to agree on an electoral roadmap within 30 days and to hold elections within three months.
The Somali government has rejected the decision.
A day before the ruling, the president dismissed Chief Justice Baashe Yusuf Ahmed. They have since challenged the dismissals at the East African regional court in Tanzania.
Mahmood says the political and security crises are closely connected, with the absence of consensus over the elections making it harder for the government to focus on the fight against al-Shabab.
Guleid also warns that the threat to Somalia's stability comes not only from the militant group but from clan-based militias increasingly challenging the federal government.
"Today, we have clan loyalists fighting alongside al-Shabab against the federal government," he says.
He adds that the country's leadership appears unable to anticipate the scale of the challenges ahead.
Who will fill the gap left by foreign partners?
Somalia's security challenges are compounded by its heavy dependence on international financial support.
Latest data from its finance ministry shows that donor grants account for two-thirds of its planned $1.36bn budget in 2026.
However, the ministry said it had only received about $314m of grants in the first nine months of the year, equivalent to just 35% of the expected annual aid.
Mahmood believes that although some international military support is declining, other partners could help bridge the gap through bilateral agreements and continued assistance.
But Guleid is sceptical that countries such as Turkey, Qatar and Egypt could quickly replace the military and financial contributions of Uganda and the US.
He argues that Somalia's dependence on external support makes it particularly vulnerable when international partners change their priorities.
That dependence has also contributed to increasingly strained relations with some foreign governments.
Somalia accuses the United Arab Emirates of funding armed groups and undermining its sovereignty, in the latest dispute involving an external power with significant security and economic interests in the country.
The UAE has rejected the criticism and hit back at the Somali leader, describing him as an "outgoing president" in reference to the dispute over his presidential mandate.
The two countries formally severed ties earlier this year, although the UAE has long been an important security and economic partner in Somalia.
For Egesa, the withdrawal of foreign troops could ultimately provide an opportunity for Somalia to demonstrate how much progress it has made in rebuilding its security institutions.
He believes the staggered departure of troops will allow Somali forces to assume responsibility gradually, while also forcing rival political factions to work together.
But Guleid remains far less optimistic.
He argues that unless Somalia addresses its military weaknesses, political divisions and growing influence of armed groups, it risks losing the security gains it has achieved in recent years.
For now, it faces the difficult task of fighting an entrenched insurgency, managing rival political interests and preparing for a contentious electoral process, all while some military partners are preparing to pull out.
Whether Somalia can withstand these pressures without renewed instability remains an open question.
You may also be interested in:

Go to BBCAfrica.com for more news from the African continent.
Follow us on Twitter @BBCAfrica, on Facebook at BBC Africa or on Instagram at bbcafrica
