Ould-Abdallah said the agreement also called for the UN to authorise deployment of an international stabilisation force.
Within 120 days, Ethiopian forces helping the government fight the Islamic Courts' Union fighters would then leave, conditional on the deployment of sufficient UN troops, he said.
The Islamic Courts' Union has denounced the opposition figures who took part in the meetings, casting doubt on the implementation of any agreement.
Hopes had dimmed after the two sides refused for days to meet face to face to discuss ways of ending 18 years of conflict in Somalia.'Arm twisting'
Al Jazeera's Mohammed Adow, reporting from Nairobi, said some of the main sticking points seem to have been overcome.
|The presence of Ethiopian troops in Somalia was |
a sticking point at the Djibouti talks [EPA]
"They agreed to the cessation of hostilities, and a halt to armed confrontation within 30 days. They also agreed that Ethiopian troops in Somalia should withdraw from the country within 120 days," he said.
"There is also another meeting to be held in Mecca, Saudi Arabia, on July 30, to discuss all other political issues that are pending."
"They have come back from the brink, and there has been a lot of arm-twisting to come to this point. But analysts have pointed out that this does not mean an end to the conflict in Somalia.
"Various groups have splintered, which means there may not be an immediate halt to the conflict."
Delegates had agreed on some issues like humanitarian aid late on Sunday, but decided to halt the discussions, with the main sticking point being the presence of Ethiopian forces, according to Ould-Abdallah.
He had persuaded teams from both sides to come twice to Djibouti in May and this month. But they declined to meet directly, until Monday's signing ceremony.
Meanwhile, clashes between Muslim fighters and Somali-Ethiopian forces killed at least 28 people over the weekend in Mogadishu.
The fighters are waging an Iraq-style campaign of roadside bombings, ambushes and assassinations.
The violence has triggered a humanitarian crisis that aid workers say may be the worst in Africa, with at least a million people displaced.
Source: Al Jazeera and agencies