MOGADISHU, Somalia - Somalia's president resigned Monday after a four-year term in which his Western-backed government failed to extend its power throughout a country crippled by infighting and a strengthening Islamic insurgency.

Abdullahi Yusuf's resignation, which comes amid deepening international pressure, could usher in more chaos as Islamic militants scramble for power -- even though the government controls only pockets of the capital, Mogadishu, and the seat of parliament in Baidoa.

Within hours of the announcement, mortar shells slammed into the streets near the presidential palace in Mogadishu, where the government maintains a token presence.

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.

The last time he lost his grip on the nation to Islamic insurgents, in 2006, he made the unpopular decision to call in troops from neighboring Ethiopia to prop up his administration. The call backfired -- Somalis saw the Ethiopians as "occupiers" and accused them of brutality.

This time, insurgents are in control of most of the country, prompting fears it could become a haven for terrorists.

The country's public institutions have crumbled and the once-beautiful 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," he said. Meanwhile, the Ethiopian troops are scheduled to pull out this week, leaving a power vacuum.

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 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. 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.