With no sure candidate to replace him, it remained unclear whether Gedi's departure would unify the interim government or set it down a new path of disarray.
''Today, I want to state that I am going to resign, that I am leaving the government,'' Gedi told parliament in the south-central trading town of Baidoa.
''I wasn't forced to resign, it comes from me. I will be here with you as a legislator.'' His remarks brought applause from legislators who for weeks have been poised for what would amount to a no-confidence vote in Gedi pushed by President Abdullahi Yusuf.
''With respect to the situation the country is undergoing, the humanitarian catastrophe facing us and the longstanding deadlock among us, I welcome the resignation,'' Yusuf told parliament.
In Washington, State Department spokesman Sean McCormack said the United States understood Gedi's resignation was made ''in the spirit of continued dialogue and national reconciliation among all Somali stakeholders.'' ''We call on the Transitional Federal Government to use this opportunity to engage with key Somali stakeholders, particularly those in Mogadishu, in a consultative process leading to the appointment of a new prime minister,'' he said in a statement.
Gedi's cabinet has been dissolved and discussions were under way as to who would sit as interim prime minister while a permanent replacement is found.
ACCIDENTAL POLITICIAN Gedi's resignation came as shells struck the capital Mogadishu for a third day, in the worst fighting in weeks between Islamist rebels and allied Ethiopian-Somali troops.
The Yusuf-Gedi rift had hindered progress by the government, the 14th attempt at installing central rule in Somalia since dictator Mohamed Siad Barre's ouster sunk the Horn of Africa country into anarchy in 1991.
Gedi tried to fight Yusuf's latest attempt to oust him by appealing for support from his powerful Hawiye clan in Mogadishu but he never got their full backing. Many Hawiye complain he was not their choice for the clan's top government position.
Yusuf hails from the rival Darod clan, and as such the prime minister had to be a Hawiye under a power-sharing agreement reached at talks in Kenya that gave birth to the government.
Those factors, diplomats and analysts say, made it difficult for the government to return to Hawiye-run Mogadishu until the Ethiopian military helped them over the New Year, only to be met by a Hawiye-backed Islamist insurgency.
That rebellion has challenged a government that has struggled to keep itself together in the best of times, while citizens of Mogadishu have fled the fighting by the thousands.
A veterinary surgeon by trade, Gedi rose from obscurity three years ago to become prime minister at the end of Somalia's peace talks in Kenya. Although he and Yusuf have shared Addis Ababa's support since they came to power in late 2004, the two have been at odds almost from the start.
They began to work together earlier this year until the rift widened again when they backed separate parties interested in Somalia's oil potential.
REUTERS GT PM0005