Sheikh Sharif Ahmed defeated 14 rivals
The election of Sheikh Sharif Sheikh Ahmed as president of Somalia marks a dramatic return for the former head of the Union of Islamic Courts administration.
Winning over the roughly 500 members of Somalia's newly expanded parliament is likely to be the easiest part of his presidency, however.
Somalia faces a daunting set of challenges: famine, poverty, chronic insecurity and lawlessness, meddlesome neighbours, and the enduring memory of numerous failed peace processes.
Sheikh Sharif defeated at least 14 other candidates including current Prime Minister Nur Hassan Hussein, commonly known as Nur Adde, who has been the driving force behind bringing the Transitional Federal Government and Mr Sharif's Alliance for the Reliberation of Somalia (ARS) together.
Mr Hussein was probably the favoured candidate of the West, but Sheikh Sharif commands considerable respect among many in Mogadishu and southern Somalia.
The most pressing problem for the new president is how to deal with the radical Islamist group al-Shabab.
So far they have shown no willingness to join the grand coalition between Sheikh Sharif's ARS and the remains of the transitional government under Mr Hussein.
They have spent the last two years building their military and financial strength and will be hard to dislodge by force.
Since the Ethiopian intervention at the end of 2006 al-Shabab has grown in size, ambition, organisation, and seems increasingly radical.
Their leaders have benefited from the bitter feelings generated by the Ethiopian intervention and are now probably the best organised force in Southern Somalia.
They have expanded their control over southern Somalia since taking control of the strategic port of Kismaayo late last year.
Baidoa, the town that until recently hosted the Transitional Federal Parliament, is for now also under their control.
Reports indicate that they are established in Mogadishu and threatening to capture the city.
The ARS and the transitional government have been negotiating in Djibouti but it is al-Shabab who have been making headlines.
In Shabab-controlled Kismayo a young girl accused of adultery was stoned to death - in fact she had been raped.
Al-Shabab have said they will also impose their version of sharia law in Baidoa and the other areas they control.
They have been destroying shrines of traditional saints across southern Somalia.
Most Somalis insist that al-Shabab does not represent traditional interpretations of Islam.
It seems highly unlikely that the international community or Somalia's neighbours would be keen to support the new president if he engages in negotiations with a group listed as a terrorist organisation by the US State Department.
His best bet may be to hope that militiamen fighting for al-Shabab can be convinced to change sides and support his government.
Somalia militiamen have been growing in strength
President Sharif cannot even count on unified support from the newly enlarged parliament.
The clearest division is between the original MPs who served under President Abdullahi Yusuf Ahmed and the new ARS MPs.
Even within these two groups there is hardly consensus, and it is likely that the new president will receive little help from politicians who in the past have only really swung into action when new prime ministers or presidents needed to be appointed.
MPs have been selected on the basis of a formula designed to ensure even representation across Somalia's different clans.
It is up to each clan to decide how to negotiate divisions within them along sub-clan lines.
Some analysts argue this system means MPs who come from the more stable north of the country will be involved in trying to solve the problems of the south.
They complain that the formula, by treating the problem as an all-Somalia one, ignores the reality - that the war is in the south and only southerners will be able to end the fighting.
As Mr Hussein and Sheik Sharif are both from the Hawiye clan, if one is president the other cannot be prime minister.
Families have been fleeing renewed fighting in Mogadishu this week
So the two men with the best chance of resolving the problems of the south cannot together hold the two most important offices of state.
More than three million people are in need of urgent humanitarian aid, millions were displaced from Mogadishu, and Somalia has been described as the world's worst humanitarian crisis.
Somalis rely on massive shipments of food aid to stay alive.
If the president wants to build popular legitimacy then he will need to address these problems.
However, providing food and medical supplies will be very difficult until some form of security is established, and without a government that can ensure the most basic services young men have little incentive not to take the $15-a-day pay cheque from the warring factions.
Finally, President Sharif should not expect to be left alone to resolve his country's crises.
The outside world has a history of interfering in Somalia's affairs.
Among a long list of interventions, the two-year Ethiopian mission and US missile strikes against terrorist targets may have been motivated by legitimate security fears, but they have almost never improved the security or humanitarian situation inside Somalia.
The new president will need to navigate a bickering parliament, a hungry population and meddling world - and face down a massive military threat from al-Shabab.
He will need a lot of luck if this is not to be just the most recent failed peace process in Somalia.
Roger Middleton works for the Africa Programme at Chatham House, a London-based foreign-policy think tank.