By Adam Mynott
BBC News, Nairobi
Kenyan President Mwai Kibaki strode out of State House in Nairobi with the opposition leader, Raila Odinga, alongside him in a symbolic display of unity.
Mwai Kibaki called for politics to be set aside when naming the new cabinet
Nearly six weeks ago, the two men agreed to form a grand coalition government to rescue their country from weeks of violence, anger and mistrust.
But the deal came close to total collapse during the past week as the two men and their followers were unable to agree on how to share power.
A month of negotiations had apparently led nowhere, but then on Saturday night word came through that a deal had at last been secured.
On the lawn of State House, as the final bars of the Kenyan National anthem drifted away on the afternoon breeze, Mr Kibaki launched into his address.
He was being watched by millions of Kenyans on television, to whom he paid tribute for their patience.
The president also congratulated Mr Odinga for "upholding the spirit of dialogue which enabled us to unlock the political deadlock".
The deadlock had been over how to share out the ministerial posts in the coalition government.
The National Accord and Reconciliation Act, which the two men had signed at the end of February, prescribed an equal share of power.
KEY CABINET POSTS
Prime Minister: Raila Odinga
Vice-President and Home Affairs: Kalonzo Musyoka
Finance Minister: Amos Kimunya
Deputy PM and Trade: Uhuru Kenyatta
Deputy PM and Local Government: Musalia Mudavadi
Agriculture Minister: William Ruto
But that had been made difficult because Mr Kibaki had already announced half a cabinet weeks earlier - including almost all the most powerful jobs.
Mr Odinga and his party, the Orange Democratic Movement (ODM), insisted an equal share of power included not just numerical parity in the cabinet, but also "portfolio parity".
At issue were the foreign affairs, cabinet affairs, energy, roads and local government portfolios.
President Kibaki and his Party of National Unity (PNU) appeared unwilling to yield anything and, with talks deadlocked Mr Odinga announced that the ODM would take no further part in any negotiations.
Getting the five cabinet posts represented "our irreducible minimum", he said.
So, when word came through that a deal had been done, the assumption was that the ODM had secured what they were after.
Mr Kibaki left the announcement of the cabinet until the close of his televised address on Sunday afternoon.
It appears that Mr Odinga has yielded much - he has certainly dipped below his 'irreducible minimum'
He announced that Mr Odinga was to be the new prime minister as expected.
Local government went to Musalia Mudavadi, one of Mr Odinga's right-hand men, who was also given one of the deputy prime minister posts.
But, foreign affairs stayed with the PNU, so too roads and energy. Cabinet affairs is no longer a cabinet position.
It appears that Mr Odinga has yielded much. He has certainly dipped below his "irreducible minimum".
Nonetheless a senior ODM official to whom I spoke said they were happy with the agreed position, and that "there had been concessions on both sides".
The ODM has secured some important posts.
James Orengo is the new minister of land. Bitter historical arguments over land lay at the heart of much of the violence which broke out earlier this year and the ODM's influence here could be crucial.
The post-election violence in Kenya left about 600,000 people displaced
It is also widely believed that the current administration will not make it through a five-year term and that ODM will be using the positions they have been allocated to plan for the next election.
Probably most important of all is what Mr Odinga makes of his new role as prime minister.
He insists it carries genuine executive power. How he wields that power and how skilful he is at making his mark right across the administration will be vital.
Given the acrimony and violence that has characterised Kenya for the past three months, the deal announced on Sunday is a momentous achievement.
The country could easily have slipped back into violence and there are many Kenyans who still feel very aggrieved.
It will be down to the politicians and their leadership to move the country back from the precipice.