Abdullahi Yusuf's resignation, which comes amid international pressure, could usher in more chaos as Islamic militants try to gain power -- even though the government controls only pockets of the capital, Mogadishu, and the seat of parliament in Baidoa.
Somalia has been beset by two decades of anarchy, violence and an insurgency that has killed thousands of civilians and sent hundreds of thousands fleeing for their lives.
"Most of the country is not in our hands," Yusuf said in a speech before parliament in Baidoa, referring to Islamic insurgents with alleged ties to al-Qaida.
When Yusuf took office in October 2004, the country had been divided into fiefdoms ruled by rival warlords since 1991, when a socialist dictator was overthrown. There were more than a dozen previous peace efforts and two previous governments, but they never managed to take effective control over the country.
Yusuf's government has never been strong.
In many ways, Yusuf is leaving Somalia much as he found it. But this time, insurgents are in control of most of the country, prompting fears it could become a haven for terrorists.
Meanwhile, all public institutions have crumbled and the seaside capital is now a gun-blasted shantytown. The lawlessness also has allowed piracy to flourish off the coast in the Gulf of Aden, one of the world's busiest shipping lanes.
In the address broadcast nationwide on the radio, Yusuf said he could not unite Somalia's bickering leadership and that the country was "paralyzed."
"After seeing all these things, I have finally quit," Yusuf said. Meanwhile, the Ethiopian troops are scheduled to pull out this week, leaving a power vacuum.
The parliament speaker will stand as acting president until parliament elects a new leader within 30 days. There have been no announcements of who might be under consideration, but many believe Yusuf's absence will allow moderate Islamist leaders into the government.
The most aggressive Islamic insurgency group, al-Shabab, has made dramatic territorial gains in recent months, and insurgents now control most of the country. The statement said it was too early to tell if Yusuf's replacement would be an improvement.
The United States accuses al-Shabab of harboring the al-Qaida-linked terrorists who blew up the U.S. embassies in Kenya and Tanzania in 1998. Many of the insurgency's senior figures are Islamic radicals; some are on the State Department's list of wanted terrorists.
The U.N. envoy to Somalia, Ahmedou Ould-Abdallah, who has been trying to salvage an ineffective peace deal in the country, welcomed Yusuf's resignation and said "a new page of Somalia history is now open."
The United Nations has brokered peace deals between the government and an opposition faction, but they have failed to quell the political and violent chaos. Al-Shabab has refused to participate in the talks.
Thousands of civilians have been killed or maimed by mortar shells, machine-gun crossfire and grenades in fighting in this arid country. The United Nations says Somalia has 300,000 acutely malnourished children, but attacks and kidnappings of aid workers have shut down many humanitarian projects.
Rights groups have accused all sides in the conflict -- Islamic insurgents, the government and Ethiopian troops -- of committing war crimes and other serious abuses.
Ethiopia's planned withdrawal of troops would end their unpopular presence and leave the administration more vulnerable to insurgents. The Ethiopians entered Somalia two years ago with the tacit approval of the United States to drive out an earlier group of Islamic insurgents.
Somalia has been ravaged by violence since warlords overthrew dictator Mohamed Siad Barre in 1991 and then turned on one another. The current transitional government was formed with U.N. help in 2004.
Yusuf, a former Somali army colonel in the 1960s, was jailed by Barre when he refused to cooperate in a coup d'etat in 1969. Although Yusuf is a member of one of Somalia's four biggest clans, the Darod, he was unpopular in Mogadishu because of his ties to Ethiopia -- one of Somalia's traditional enemies.
Elizabeth Kennedy reported from Nairobi, Kenya. Associated Press writers Mohamed Sheikh Nor in Mogadishu and Malkhadir M. Muhumed in Nairobi also contributed to this report.