International observers agreed that December's election count was flawed.

The post-election violence saw thousands of people targeted because they belonged to ethnic groups seen as either pro-government or pro-opposition. About 600,000 people fled their homes.

Although the level of violence had fallen in recent weeks, there were concerns that a failure to reach a deal would lead to a fresh round of blood-letting.

Negotiations between the government and opposition lasted more than a month, stalling several times.

The BBC's Adam Mynott, in Nairobi, says both sides have given ground from their original positions to reach this agreement.

Portfolios shared

The new coalition will be headed by President Kibaki, with Mr Odinga - whose Orange Democratic Movement (ODM) is the largest in parliament - probably taking the newly created post of prime minister.

Compromise was necessary for the survival of this country

Kofi Annan

Each party will nominate a deputy prime minister, with other ministerial portfolios being divided equally between the two parties.

Correspondents say both parties are now likely to begin wrangling over who gets what position in the new government, with the post of finance minister likely to prove the most contentious.

After the deal was reached, Mr Annan said: "Compromise was necessary for the survival of this country."

He urged all Kenyans to support the agreement, saying: "The job of national reconciliation and national reconstruction is not for the leaders alone. It must be carried out in every neighbourhood, village, hamlet of the nation."

'New chapter'

Speaking after the signing, Mr Kibaki said: "This process has reminded us that as a nation there are more issues that unite than that divide us...

"We've been reminded we must do all in our power to safeguard the peace that is the foundation of our national unity... Kenya has room for all of us."

A spokesman for the US state department, Tom Casey, said the agreement was "an important and very positive step forward".

He added: "It allows the Kenyan people to move forward with a very basic issue of governance."

British Prime Minister Gordon Brown welcomed the new power-sharing agreement.

"Kenya's leaders have reached a power-sharing agreement that represents a triumph for peace and diplomacy, and a renunciation of the violence that has scarred a country of such enormous potential," he said.

In western Kenya, the scene of the some of the worst violence, there was some scepticism about the agreement.

Paul Waweru, 56, who fled his home and is now living in a camp in Eldoret, said: "The deal between Raila and Kibaki will help to cool down the situation but I doubt if it will enable us to get back to our homes."

But in Nairobi's Kibera slum, there were celebrations.

"The general mood among people is that of happiness," said Nelson Ochieng.

"We are tired of the political crisis. I was a barber but my shop was burnt. Now I'm jobless, and the end of this crisis means that I can rebuild my business."