Somalia's government signed an agreement Monday with an opposition alliance calling for an end to violence and the withdrawal of Ethiopian troops as the country tries to emerge from more than a decade of anarchy.

The agreement, struck during U.N.-led talks in neighboring Djibouti, is an important step toward ending an increasingly bloody Islamic insurgency. But it remains to be seen if the deal will be respected by hardline members of the opposition, who have denounced those who took part in the talks.

"The primary requirement of this agreement is to ensure the cessation of all armed confrontation and a political settlement for a durable peace," said a copy of the deal obtained by The Associated Press.

The government's agreement with the Alliance for the Re-Liberation of Somalia came after hours of rumors that the talks had collapsed over the issue of Ethiopian troops. The opposition sees the troops — who have been in Somalia since 2006 to help government forces deal with an Islamic insurgency — as an occupying force.

But late Monday, both sides agreed to "end all acts of armed confrontation" and to withdraw Ethiopian troops from the country within 120 days.

Members of the U.N. Security Council visited Djibouti last week to encourage Somalia's government and the opposition alliance to hold direct peace talks.

Somalia has been in a state of anarchy since warlords overthrew dictator Mohamed Siad Barre in 1991 and then turned on each other, sinking the poverty-stricken Horn of Africa nation of 7 million people into chaos.

The shaky transitional government formed in 2004 called in troops from neighboring Ethiopia in December 2006 to oust Islamic militants who had seized control of the capital, Mogadishu, and most of southern Somalia.

A vicious insurgency started soon after, and remains a potent and disruptive force in the country and a continuing threat to the government, which is backed by both the European Union and United States.

Meanwhile, the country is facing a worsening humanitarian crisis aggravated by high global food prices, drought and a collapsed economy.