President Barack Obama is set to announce the first American ambassador to Somalia since the civil war erupted more than 20 years ago, according to a US diplomat.

"As a reflection both of our deepening relationship with the country and of our faith that better times are ahead, the president will propose the first US ambassador to Somalia in more than two decades," Under Secretary of State for Political Affairs Wendy Sherman told a US think tank on Tuesday.

Sherman would only say the announcement from Obama, who is in Europe, was expected "soon" and confirmed that, initially, the new ambassador would be based in Nairobi, Kenya.

Although the US never formally severed ties, the embassy in Mogadishu was closed in 1991 as Somalia descended into chaos amid a bloody power struggle among brutal clan chiefs.

Dark history

The darkest chapter in ties came in 1993 when the bodies of US soldiers were dragged through the streets of Mogadishu by a mob after fighters loyal to Mohamed Farah Aideed, who was on US wanted list, shot down two Black Hawk helicopters.

Thousands of Somalis and 18 American soldiers died in the ensuing battle between fighters loyal to the Aideed and US soldiers.

The Somali government that finally took power in August 2012 was the first to be given global recognition since the regime of dictator Siad Barre fell in 1991. The US recognised the new government in January, 2013.

But while the new Somali government controls the capital Mogadishu, large swathes of rural areas are controlled by the al-Qaeda linked al-Shabab rebel group, which wants to impose strict Sharia law in the east African country.

Recent al-Shabab attacks have targeted key areas of the Somali government, including an attack on the parliament last month, in an apparent bid to discredit claims that they are winning the war against the rebel fighters.

In September, al-Shabab carried out its most high-profile attack to date - a daring assault on Nairobi's Westgate shopping mall that left at least 67 dead.