Funny how things work out. Two years ago Sheikh Sharif Sheikh Ahmed was on the run from an Ethiopian assault that had snatched Mogadishu from the Islamists who ran the city peacefully for six months. America had given its tacit support to the strike, fearing that Somalia was about to become a haven for al Qaeda. Sheikh Sharif was a wanted man.
Now he is president of Somalia, or at least that part of Somalia controlled by an alliance of the old discredited Transitional Federal Government and Sheikh Sharif's moderate wing of the Islamist Alliance for the Reliberation of Somalia.
He was chosen by the country's MPs meeting in Djibouti, a result that will be something of an embarrassment for the West. British diplomats in particular were lobbying hard for his rival Nur Adde. Yet for anyone who wants peace in Somalia it has to be the right result.
Nur Adde may be the better politician, with his years of experience as an aid official. But Sheikh Sharif is the man who can unite the country. The new president faces an Islamist insurgency that has wrested control of large chunks of the country. If he can survive the initial onslaught that is sure to come from extreme opposition movements, and start to show momentum, bringing in donor cash and showing that his is the only game in town, he stands a chance of bringing his old allies in the Union of Islamic Courts on board.
The man I met two and a half years ago in a battle-scarred city struck me as a man prepared to talk. He wanted to tell the world that he was not a terrorist or an extremist but a man who wanted to make Somalia a better place. He and the Islamic Courts brought peace and security to a city that had experienced nothing but anarchy for a decade and a half.
He was anything but a cartoon Islamist. With his checked shirt, cargo pants and headscarf he looked more like Islamist by Gap.
His problem was that extremists within his movement went too far. Some of the Sharia courts within the union banned music in their areas of the city, cinemas were shut down and - the biggest mistake of all - stopped the trade in qat, the mild stimulant so beloved of Somali men. With popularity at home ebbing and little support from the international community Sheikh Sharif was unable to sideline the hardliners like Sheikh Aweys and the project was ultimately doomed.
This time around he faces the opposite challenge, bringing al Shabaab - designated a terrorist outfit by the State Department and which controls big chunks of Somalia - and Sheikh Aweys on board. It will be tough but he stands a better chance than Nur Adde, a former prime minister of the hated TFG, which is seen as a stooge of Ethiopia and western powers.
If there's one thing I've learned about Somalia in four years of reporting (aside from the fact that anyone who tells you they know what they are talking about is a fool) is that nothing will work unless it comes from Somalia itself. The British diplomats haven't learned that lesson, trying to dabble in Somalia's political process to promote their man (he has a Brit passport too) at the expense of Islamists.
Somalis generally throw in their lot with whoever looks like winning. Analysts tell me al Shabaab's strength is overestimated. So if Sheikh Sharif can hold on to a fractious bunch of MPs, start to bring order to Mogadishu as he did once before, clans will start coming in behind him. They have a well-attuned radar for knowing which side their bread is buttered. For now, at least, one of the men demonised by the West is Somalia's best chance of peace.
This was cross-posted on Frontline Club.