Kenyan President Mwai Kibaki and opposition leader Raila Odinga have signed an agreement to end the country's post-election crisis.
At a ceremony in Nairobi, the two men put their signatures to a power-sharing deal brokered by ex-UN head Kofi Annan.
A coalition government comprising members of the current ruling party and opposition will now be formed.
Some 1,500 people died in political violence after Mr Odinga said he was robbed of victory in December's polls.
New two-party coalition government to be set up
Cabinet posts to be divided equally between parties
Raila Odinga to take new post of prime minister, can only be dismissed by National Assembly
Two new deputy PMs to be appointed, one from each member of coalition
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.
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.
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."
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."
Mr Odinga said: "With the signing of this agreement, we have opened a new chapter in our country's history - from the era or phase of confrontation to the beginning of co-operation.
"We, on our side, are completely committed to ensuring that this agreement will succeed."
Both men thanked those who had stood by Kenya in what Mr Odinga called its "hour of need", including Mr Annan, the African Union, the European Union, the United States and the UN.
They also urged Kenyans to move forward together without ethnic divisions.
'Very basic issue'
HAVE YOUR SAY
After 8 weeks of uncertainty in the political atmosphere as well as peace, there is somehow a glimpse of hope and light to the beautiful land of Kenya.
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."