In 2006, Islamic groups in Mogadishu fought fierce battles against a combined force of the warlords and defeated them. The groups, known as the Union of Islamic Courts (UIC), initially enjoyed considerable civilian and business support from a community fed up with insecurity in areas controlled by the warlords, including the capital.
The UIC ranks contained both radical elements, in the form of Al-Shabab, and moderate members, but the radicals were a small minority. From June-December 2006, it brought unprecedented calm to Mogadishu and other areas of south and central Somalia.
In December 2006, Ethiopian forces, with backing from the United States - which regarded the UIC as a terrorist organisation - entered Somalia and installed the Transitional Federal Government (TFG) in Mogadishu, where it had hardly made its presence felt since coming into being in 2004 after two years of talks in Kenya.
Subsequently, fierce fighting continued between UIC remnants, including Al-Shabab and their supporters, and the combined forces of Ethiopia and the TFG. Hundreds of thousands of civilians were forced to flee their homes.
In December 2008, the Ethiopians withdrew from Somalia, leaving a small African Union (AMISOM) force to defend the government.
In January 2009, a peace deal signed in Djibouti between the UN-backed TFG and a faction of the opposition, the Alliance for the Re-liberation of Somalia (ARS) saw the creation of a parliament which elected Sheikh Sharif Sheikh Ahmed http://www.irinnews.org/Report.aspx?ReportId=82900 as president of the TFG. The former UIC chairman was considered by many as a moderate Islamist.
Many Somalis hoped Ahmed's election and the departure of Ethiopian troops would end the violence and launch a new era of peace in the country. They were wrong.
Ahmed's government was opposed by a breakaway group from his own ARS, led by his former ally Sheikh Hassan Dahir Aweys. Aweys, who was based in Asmara, Eritrea, returned to Somalia and set up Hisbul-Islam (Party of Islam).
The Djibouti peace deal was also opposed by Al-Shabab, which had long split from the main UIC.
Whereas previous struggles for power in Somalia were fought along the lines of the country's complex clan system, the current conflict is, ostensibly at least, a war between groups with different interpretations of Islam.
TFG forces comprise fighters who used to serve various warlords, former members of the UIC, clan militia and Ethiopian-trained forces. These disparate groups have weak central command and control, despite the government's efforts, so are rarely able to carry out a coordinated attack. There have been incidents of fighting between the different units.
The main threat to the TFG is posed by Al-Shabab. It is on a US terror list and is accused of having links with Al-Qaeda. The group controls much of southern and central Somalia, including parts of Mogadishu. Al-Shabab is reportedly led by a shadowy figure who goes by the name of Abu Zubeyr. His real name, according to Somali sources, is Ahmed Godane and he is originally from secessionist Somaliland. His main contact is through taped messages given to Somali radio stations. The group's professed aim is to spread Islam across the globe.
The movement has been accused of kidnapping, assassinating government officials and journalists, and other criminal activity.
While a keynote of Al-Shabab's official rhetoric is that clan affiliation and geographic origin should play no part in governance, and that any Somali should be able to serve as "amir", or leader, in any part of the country, this policy does not appear to be followed in central Somalia, where only locals are appointed amirs.
Al-Shabab views President Ahmed as a traitor to the Islamic cause and has described him and his government as "Murtadiin" (apostates). It believes in the strict application of Sharia law.
Like Al-Shabab, Hisbul-Islam is also fighting the TFG but is not known to engage in kidnapping and assassinations. It also differs in outlook. Hisbul-Islam is inward-looking and concerned with local rather than international issues, according to Somali analysts. Aweys, its leader, considers the Djibouti peace deal a betrayal. The group is reportedly supported by Eritrea, a charge Eritrea consistently denies.
Hisbul-Islam insists it will stop fighting if all "foreign forces" leave Somalia, including AMISOM troops.
Ahlu Sunna Waljama is a Sufi sect, regarded as more moderate in its interpretation of Islam than Al-Shabab. It joined the fighting in late December 2008, dislodging Al-Shabab from the towns of Guri-Eil and Dusamareb in Galgadud region. It now controls all of Galgadud in central Somalia.
Ahlu Sunna Waljama has two branches. The first was formed by Sufi clerics and enjoys support from Ethiopia. This branch is mainly concentrated in central regions. The other is led by former warlords, who apparently are using the name to reinvent themselves. This group is mainly in the south around Gedo, Bay and Bakol regions. They have some links to the TFG.
AMISOM, staffed mainly by troops from Uganda and Burundi, has been in the country since 2007. In the past the force was confined to protecting the president and prime minister and vital infrastructure, such as the airport and port. In recent months its troops have been drawn into the fighting as insurgents targeted them. Somalis have accused the force of indiscriminate shelling when responding to attacks, a charge they deny.
The 5,000 or so AMISOM troops, supported by the US and UN, are concentrated in Mogadishu.
In January 2009, Ethiopia said it had completed the withdrawal of its forces from Somalia. Since then there have been reports, denied by the Ethiopians, of Ethiopian troops in parts of central Somalia. Local sources in Beletweyne town told IRIN Ethiopian forces entered the town on 28 August and are still there.