Mogadishu - Moderate Islamist leader Sheikh Sharif Ahmed has been elected Somalia's new President, after a secret ballot of Members of Parliament.
President Ahmed won a majority in a second round of voting after one of the frontrunners, Prime Minister Nur Hassan Hussein, withdrew. The election followed the resignation of President Abdullahi Yusuf Ahmed.
MPs met in neighbouring Djibouti due to the instability in Somalia, where Islamist militias control much of the country.
Mr Ahmed was, until recently, the leader of an opposition movement accused of having links to al-Qaeda.
A local media have claimed he won the election because is the only person who can straddle the political extremes between the secular warlords, who until now have dominated government, and the Islamist al-Shabab militia.
He was sworn in as president on Saturday, before heading off to the African Union Summit in Ethiopia to represent Somalia.
Earlier this week, 149 new opposition members from the Alliance for the Re-Liberation of Somalia (ARS), which is led by Ahmed, were sworn in to Parliament.
However, al-Shabab has said it will not recognise the new government. Al-Shabab militiamen control the former seat of parliament, Baidoa, and many other parts of central and southern Somalia.
Mr Yusuf resigned as President in December. He had been accused by the Prime Minister and Parliament of being an obstacle to peace in the country. Somalia has not had a functioning central government since 1991, and the northern regions of Somaliland and Puntland have broken away to govern themselves.
Tens of thousands of people have been killed in successive waves of violence, more than a million people have fled their homes and 43 percent of the population, or 3.5 million people, is in need of food aid.