Abdullahi Yusuf was appointed president four years ago
Somalia's President Abdullahi Yusuf has resigned - a move which adds to the chaos in the country as Ethiopian troops are to withdraw shortly.
Mr Yusuf's resignation follows a power struggle with Prime Minister Nur Hassan Hussein, who parliament backed after Mr Yusuf tried to sack him.
Various Islamist and nationalist groups control most of southern Somalia.
Some experts say Mr Yusuf's departure could make it easier to reach a peace deal with moderate Islamists.
The president had clashed in recent months with Mr Nur over attempts to negotiate a peace deal with the Islamist-led armed opposition.
BBC Somali service editor Yusuf Garaad says the president's departure has removed one obstacle to peace but it is unclear what happens next, especially if the government collapses altogether.
Mr Yusuf is reported to have flown out of Baidoa, where parliament is based, to his home region - the semi-autonomous area of Puntland in the north.
Under the constitution, speaker of parliament Aden Mohamed Nur becomes acting president until MPs elect within 30 days a new president, who will then nominate a new prime minister.
Mr Yusuf was chosen by MPs four years ago at the end of a long process that was supposed to bring peace to Somalia, which has not had an effective national government since 1991.
But government forces only control parts of the capital, Mogadishu, and the town of Baidoa.
Mr Nur - the prime minister Mr Yusuf tried to sack - appeared pleased with the president's resignation, say a BBC correspondent in Mogadishu.
"We welcome the resignation of the President Abdullahi Yusuf as a democratic step forward taken by Somalia," he said.
Al-Shabab is fighting a relatively new rival Islamist militant group
Meanwhile, a relatively new self-styled moderate Islamist group, Ahlu Sunna Waljamaca, which seized two towns in central Somalia over the weekend, continued to fight militants from the hardline al-Shabab on Monday.
Ethiopian government spokesman Bereket Simon told the BBC's Focus on Africa programme that Ethiopia had had nothing to do with Mr Yusuf's departure and it would not affect plans for Ethiopian troops to leave Somalia.
The BBC's Mohammed Olad Hassan in Mogadishu says no-one has publicly declared their candidature to succeed the president.
A weary-looking Mr Yusuf told MPs in Baidoa: "As I promised when you elected me on October 14, 2004, I would stand down if I failed to fulfil my duty, I have decided to return the responsibility you gave me."
'Obstacle to peace'
In his speech, broadcast on national radio, he said: "When I took power I pledged three things.
"If I was unable to fulfil my duty I will resign. Second, I said I will do everything in my power to make government work across the country. That did not happen either.
"Third, I asked the leaders to co-operate with me for the common good of the people. That did not happen," he said, according to Associated Press news agency.
Last week, Mohamed Mahamud Guled, who Mr Yusuf tried to install as prime minister, resigned saying his appointment was destabilising the government.
Mr Yusuf had faced criticism for appointing Mr Guled in defiance of Somali MPs, who overwhelmingly rejected the dismissal of his predecessor.
Mr Guled said he had chosen to resign "so that I am not seen as a stumbling block to the peace process which is going well now".
The regional grouping, Igad, which brokered the talks leading to Mr Yusuf's election, this month imposed sanctions on him, calling him an obstacle to peace.
Fighting between the Ethiopia-backed government and the insurgents has left some one million people homeless and much of Mogadishu deserted.
Some three million people - a third of the population - need food aid.
And the lack of leadership has led to a surge in piracy off the Somali coast.
A small African Union peacekeeping force is based in Mogadishu but analysts say they would be unable to withstand an Islamist advance.
The UN has rejected calls to send its own mission to Somalia.