AT FIRST glance Somalia’s foreign-backed government seems to be doing well. In the past two years it has benefited from the recovery of the country’s main cities by African Union peacekeepers after two decades of clan warfare and intermittent Islamist rule. And on June 29th the government pulled off something of a coup by locking up the grandfather of militant Islamism in Somalia, Sheikh Hassan Dahir, better known as Aweys. The red-bearded 78-year-old may be the victim of infighting in the Shabab, an al-Qaeda-linked movement that is steadily losing power but can still cause mayhem with suicide-bombings here and there.

But appearances may mislead. President Hassan Sheikh Mohamud, appointed last year to much acclaim, is accused of employing warlords to assert his authority over the fragmented country. A report due to be submitted to the UN Security Council by independent experts says the government used rival militia leaders to gain control of Kismayo, the second city. The report alleges that Mr Mohamud, who gets a lot of cash from Western governments, has been “co-opting clan warlords”, some of them linked to the Shabab.

The region around the capital, Mogadishu, remains more or less in government hands. But southern Somalia is engulfed in a power struggle. Five rival militia leaders proclaim themselves “president of Jubaland”, a region that includes Kismayo. At least 40 people were killed last month when clashes broke out between them. The most powerful is Sheikh Ahmed Madobe, whose Ras Kamboni brigade helped the Kenyan army to drive the Shabab out of Kismayo last year. With Kenya’s implicit backing, he has refused to let representatives from the federal government enter Kismayo. His main rival is Barre Hiraale, another warlord who has sometimes sided with the Shabab.

The struggle pits against each other two of Somalia’s most powerful clans, the Darod of Sheikh Madobe and the Hawiye of President Mohamud. Conflict between the “superclans”, as well as internecine battles among myriad subclans, has fuelled Somalia’s civil war for two decades.

In this context, the humiliating arrest of Sheikh Aweys may turn out to be counterproductive. He was promised talks with government officials but instead was arrested and roughed up by soldiers. This could split the Hawiye clan, of which the president and the arrested Islamist are both members.

To make matters even worse, the Shabab appear less divided than was thought. Following recent infighting, one aspiring leader was killed and Sheikh Aweys was arrested, leaving sole command to Ahmed Abdi Godane, who is regarded as being keenest within the Shabab on its alliance with al-Qaeda. On June 19th Shabab suicide-bombers breached the front gates of the UN compound in Mogadishu; gunmen barged in and killed at least nine people. Nick Kay, a Briton recently appointed as the UN’s special envoy to Somalia, gamely insisted there would be no retreat in the face of the assault.