Updated

Ethiopia announced Friday that is pulling its forces from Somalia by year's end, leaving the ravaged capital vulnerable to the Islamic militants who have seized nearly all of the country.

The decision ends the unpopular two-year presence of the key U.S. ally much as it began — with the militants in near-total control of a failed state with a worsening humanitarian crisis.

Ethiopia has sent thousands of troops here since early 2007, when it launched a U.S.-backed operation that drove the militants from Mogadishu after six months in power.

Since then, the Islamists have waged a ferocious insurgency, attacking U.N.-supported Somali government troops and their Ethiopian allies nearly every day.

The United States worries that Somalia could be a terrorist breeding ground, particularly since Osama bin Laden declared his support for the Islamists. It accuses a faction known as al-Shabab — "The Youth" — of harboring the al-Qaeda-linked terrorists who allegedly blew up the U.S. Embassies in Kenya and Tanzania in 1998.

Ethiopian forces have remained almost entirely in the capital, along with a small African Union force that has just 2,600 of the intended 8,000 troops and has largely been confined to urban bases.

The militants, meanwhile, have taken control of towns within miles of the capital and move freely inside Mogadishu.

Ethiopia and the Somali government have called without success for a United Nations peacekeeping force to help pacify the country and boost the weak government. The U.N. Security Council has said that it would consider sending peacekeepers to replace AU forces if Somalia can improve security and achieve political reconciliation.

Ethiopian Foreign Ministry spokesman Wahide Bellay said Ethiopia would wait no longer.

"Regardless of what happens, we have decided to withdraw our troops from Somalia at the end of year," Bellay said in a telephone interview from Addis Ababa, Ethiopia.

Dr. Ken Menkhaus, a Somalia expert at Davidson College in North Carolina, called the Ethiopian withdrawal "inevitable" and said Somalia's Transitional Federal Government would be driven from the capital once its allies depart.

"There was never any serious prospect of a U.N. peace operation," Menkhaus said. "The TFG will not be able to maintain even a token presence in Mogadishu."

Calls for comment from the Somali government were not immediately returned.

Somalia's transitional government was formed in 2004, but has failed to assert any control over the country. Somali President Abdullahi Yusuf has acknowledged that it is close to collapse.

Civilians have taken the brunt of the violence — thousands have been caught in the crossfire, killed or maimed by mortar shells, machine-gun fire and grenades. Hundreds of thousands have fled Mogadishu, as Islamic extremists allied to al-Shabab have gained power.

"The AU deplores the fact that the United Nations has not acted," the AU envoy to Somalia, Nicholas Bwakira, told The Associated Press. "We are still hoping that the United Nations will act because if it does not act and they allow a security vacuum, the security situation might deteriorate further. It is already bad and will deteriorate further."

A U.N. peacekeeping operation in the early 1990s saw the downing of two U.S. Army helicopters and killing of 18 American soldiers. The U.S. withdrew and U.N. peacekeepers were gone by 1995.

The Pentagon sent a small number of Special Operations troops with the Ethiopian forces in 2006, and in early 2007 the U.S. conducted several airstrikes in an attempt to kill suspected al-Qaida members.

Now, it seems, the Ethiopians have had enough open involvement in an unpopular war.

The Ethiopian has long said it wanted to withdraw after stabilizing its neighbor.

But its opponents say the mainly Orthodox Christian country with a Muslim minority was interested mainly in preventing an Islamist regime next door.

Ethiopia has one of Africa's largest armies, which many Somalis have seen as abusive and heavy-handed.

Rashid Abdi, an analyst at the International Crisis Group think tank, said the Ethiopians could simply seal the border with troops and air power.

"They can continue to make military incursions across the border without troops on the ground who will be open to attack," Abdi said.