Al-Shabab rebels control large parts of Somalia
By Peter Greste
BBC News, Nairobi
With few friends at home and abroad, Abdullahi Yusuf had little choice but to quit as Somalia's president.
His decision to go could not have come at a more critical point for Somalia.
In his nationally broadcast resignation speech, Mr Yusuf reminded Somalis of the promise he had made when he was elected more than four years ago.
"When I took power, I pledged three things," he said.
"If I was unable to fulfil my duty, I will resign.
"Second, I said I would do everything in my power to make government work across the country. That did not happen either.
Yusuf's resignation also makes it much easier to build a new, more moderate and inclusive government
"Third, I asked the leaders to co-operate with me for the common good of the people. That did not happen."
There is no doubt President Yusuf failed on all of those counts.
The radical al-Shabab rebels now control almost all of central and southern Somalia, apart from a few districts of Mogadishu and the town of Baidoa where the government is based.
But it is the third pledge - to get the support of parliament - that ultimately triggered his departure.
Abdullahi Yusuf admitted that he had failed to fulfil his three pledges
President Yusuf had been locked in a bruising power struggle with his Prime Minister Nur Hassan Hussein for months, particularly over the prime minister's attempts to draw moderate Islamists into the government.
Two weeks ago, he tried to sack Prime Minister Nur, only to have parliament declare the dismissal unconstitutional, and then pass a vote of confidence in the prime minister.
At the same time, Somalia's neighbours turned on the president, accusing him of being the chief obstacle to peace.
On 5 January, Ethiopia is due to withdraw the last of its troops from Somalia.
Along with a handful of African Union troops from Uganda and Burundi, they have been one of the few shields protecting the Somali government from the al-Shabab rebels.
There is still no sign that the Ethiopians are packing up, and they may yet decide to delay their departure once more.
But publicly at least, they are still sticking to the 5 January deadline, and assuming they are going, diplomats have sensed an opportunity.
"If there's one thing that al-Shabab has been able to use to get support, it's the Ethiopian presence," said one western diplomat who declined to be named.
"Nobody in Somalia trusts their motives, so it's been easy for al-Shabab to use them as a rallying point. But if they go, it will make it much harder for [the Islamists] to hold on to that support.
"Yusuf's resignation also makes it much easier to build a new, more moderate and inclusive government which is what Prime Minister Nur has been trying to do all along."
In a statement, the UN's Special Representative for Somalia, Ahmedou Ould Abdallah, pointed out that: "It is the first time in Somalia's modern history that a president has decided to leave office peacefully."
It was, he said, "a patriotic and courageous decision".
But he also invited Somalis both inside the country and abroad to "take this opportunity to rise above their differences".
He said it is a time for unity and solidarity.
That is largely because both the president's resignation and the Ethiopian withdrawal also present a great danger for Somalia.
There is now a real danger that unless the international community led by Mr Abdallah can build a solid and stable government soon, the rival factions will once again tear the country up in a new struggle to fill the power vacuum.
It may already be too late.
On Monday, a relatively new group, Ahlu Sunna Waljamaca was engaged in fighting al-Shabab after it seized two towns in central Somalia over the weekend.
Ahlu Sunna Waljamaca presents itself as a moderate Islamic organisation, and it has pledged to oust al-Shabab altogether - something that some analysts say points to a growing resentment of the hardliners.
But experienced observers say the newcomers look more like a cover for a collection of clan-based warlords trying to exploit the current political and military upheaval than a genuine force of clerics.
Either way, Somalia is faced with yet another period of violence that is far more likely to hurt the civilians already struggling with some of the worst humanitarian conditions in the world, than it is the politicians.