Ethiopia has said it will withdraw its troops from Somalia by the end of this year, ending a presence that aggravated an Islamist insurgency and raising pressure on the international community to fill a security gap.

Ethiopia invaded at the end of 2006 to oust Islamists who had seized power, but it has grown impatient defending an interim government that has failed to establish control beyond a few blocks of Mogadishu.

The piracy flourishing off Somalia is viewed as one expression of the violent lawlessness that has spread across the country since Ethiopia defeated the Islamic Courts Union.

The pirates are not likely to be affected directly by an Ethiopian withdrawal because they operate from Puntland, a region where the Ethiopians have never had a presence. Some analysts have said that an Ethiopian withdrawal could trigger the collapse of the divided interim government and create a power vacuum that would be filled by Islamists who have waged a campaign of roadside attacks.

Ethiopia’s foreign ministry said yesterday the government had announced its withdrawal in a letter sent on Tuesday to Ban Ki-Moon, the United Nations secretary-general, and Jean Ping, chairman of the African Union commission.

Meles Zenawi, Ethiopia’s prime minister, signalled a shift in his stance in August when he said he was prepared to withdraw even if the interim government were not stable or functioning.