MOGADISHU, Somalia - Ethiopia handed over security duties in neighboring Somalia on Tuesday to a joint force of Somali government security forces and Islamic militiamen, a shift some fear will leave a power vacuum in the lawless African nation.

Somalis overwhelmingly welcomed the Ethiopians' withdrawal despite any guarantee that the Islamists would be able to restore peace.

The Ethiopian troops have been propping up Somalia's weak UN-backed government for two years amid a ferocious Islamic insurgency that has killed thousands of civilians and prompted the president to resign in December, saying he had lost the country to the Islamists.

The lawlessness also has allowed piracy to flourish off Somalia's coast. Last year, pirates seeking multimillion-dollar ransoms attacked 111 ships in the Gulf of Aden and seized 42 of them.

But the Ethiopians had said they would to end their unpopular presence as demanded under an October power-sharing deal signed between the Somali government and a faction of the Islamists.

"It is time Somalia stands on its own feet," said Ethiopian commander Col. Gabre Yohannes Abate, as he handed over security operations during a ceremony at the presidential palace in Mogadishu. "So we are saying goodbye to all Somalis and their dignitaries."

It was unclear when all of the thousands of Ethiopians will have departed. They were pulling out in stages, rather than all at once, and gave no exact dates for security reasons.

The pullout has received wide support from ordinary Somalis, officials and diplomats. Many had seen the Ethiopians as occupiers, and their two-year deployment has been a rallying cry for the insurgents to gain recruits even as the militants' strict form of Islam terrified people into submission.

"The insurgents have been fighting for the withdrawal of Ethiopians all this time," Prime Minister Nur Hassan Hussein said during the handover. "When the Ethiopians have begun withdrawing, there is no need for fighting again. I urge all Somalis to become peace-loving people."

The government called in the Ethiopian troops in December 2006 to oust an umbrella Islamic group that had controlled southern Somalia and the capital for six months.

Many saw the Ethiopian army, one of Africa's largest, as abusive and heavy-handed. Ethiopia long said it wanted to pull out after stabilizing Somalia, but opponents said Ethiopia -- a mainly Orthodox Christian country -- was interested in preventing an Islamist regime in neighboring Somalia.

The two countries have been rivals for decades, and fought over a southeastern region of Ethiopia populated principally by people of Somali origin.

Some feared the Ethiopians' departure would allow the strengthening Islamic insurgency to further take over. On Monday, Islamic insurgents attacked the presidential palace, resulting in heavy fighting with government troops, during which at least 11 civilians were killed.

The Islamist groups, once unified, have split since gaining more territory last year. They have begun fighting one another for control of several towns, with the government-allied Islamists claiming to be in charge of some of them.

Last year, Somalia's transitional government agreed to share power with a faction of the country's opposition, the Alliance for the Re-Liberation of Somalia, a relatively moderate group that split from the al-Shabab extremist group which has been at the center of the insurgency.

But al-Shabab, which the U.S. considers a terrorist organization, did not participate in the UN-brokered talks.

Hussein Siyad Qorgab, deputy chairman of the alliance faction, urged all to "come together and make a unity government."

"We are happy to see Ethiopian troops withdraw from Somalia ... we need to see them off, but we do not need to see them off with mortars or fighting," Qorgab said.

The UN envoy to Somalia praised the Ethiopians for honoring of a withdrawal commitment made with the power-sharing deal signed last year in Djibouti.

"The ball is now in the court of the Somalis, particularly those who said they were only fighting against the Ethiopian forces, to stop the senseless killings and violence," Ahmedou Ould-Abdallah said in a statement issued Tuesday in neighboring Kenya.

Fadumo Wehliye, who lost three of her eight children during the violence, described the Ethiopian pullout as "great" and said she would go back to home in Mogadishu.

"For the last two years ... I have been living in a makeshift house in the outskirts of the capital," she said. Now "I will return to my home."