Sheik Sharif Sheik Ahmed was elected in neighboring Djibouti early Saturday after the last president - a former soldier, rebel and warlord named Abdullahi Yusuf - resigned in December after failing to pacify the country during his four-years as president.
More than 1,200 people, including the new Somali parliament, attended Saturday's swearing-in at a hotel in Djibouti.
Ahmed was chairman of the Islamic Courts Union that ran Mogadishu for six months in 2006 before Ethiopian soldiers drove them from power. His election raises hopes that he will bring many of Somalia's Islamic factions into a more inclusive government.
But the Western-backed government wields little control in Somalia - just a few blocks of the capital, Mogadishu, where African Union peacekeepers patrol. An Islamic insurgent group called al-Shabab, who say they don't recognize the government, have taken over most of Somalia.
The U.S. considers al-Shabab a terror organization with links to al Qaeda.
The U.S. government congratulated Ahmed on his election, saying he has worked diligently on reconciliation efforts in Somalia.
"We urge President Sharif to reach out to the broad spectrum of Somalis who reject violence and extremism in forming a new government," the U.S. Embassy in Nairobi, Kenya said in a statement. "We encourage all Somalis to support the president and his government," it added.
Somalia's parliament has been meeting all week in neighboring Djibouti to choose the new president. Sharif won easily with 293 votes after the other front-runner, the prime minister, withdrew. The second-place candidate received 126 votes.
Sharif was due to fly to the Ethiopian capital for an African Union summit after he was sworn in.
The arid and impoverished Horn of Africa nation of some 8 million people has not had a functioning government for a generation, since clan-based militias overthrew a dictator in 1991 then turned on each other.
Pirates prey on international shipping freely from Somalia's lawless shores, and analysts fear an extremist Islamic administration could become a haven for international terrorists.
There have been more than a dozen previous peace efforts and three previous governments were formed, but they never managed to take effective control over most of the country.