A deal to form a government of national unity in Afghanistan has been signed at a ceremony in Kabul.
The signing – broadcast live on national TV – comes after months of wrangling following presidential elections in April and June.
Under the deal, Ashraf Ghani becomes president while runner-up Abdullah Abdullah nominates a CEO with powers similar to those of prime minister.
The final result of the bitterly contested poll is due to be announced.
Both sides had accused the other of fraud following the election.
Ghani and Abdullah signed the agreement at a ceremony inside the presidential palace in the capital, Kabul. They then stood and embraced each other.
Outgoing Afghan President Hamid Karzai congratulated the two men, saying that the agreement was “for the progress and development of this country”.
“On behalf of the Afghan nation, I am congratulating them on this understanding and agreement,” he said in his speech.
The US hailed the deal as an “important opportunity for unity”.
“We support this agreement and stand ready to work with the next administration to ensure its success,” White House spokesman Josh Earnest said.
The power-sharing deal was finally reached after a comprehensive audit of all eight million votes, brokered by US Secretary of State John Kerry.
BBC Afghanistan correspondent David Loyn, who has seen a copy of the agreement, says it averts potential violence by supporters of Abdullah.
The agreement says the new CEO will be answerable to Mr Ghani, although he has lost a battle to be sworn in after the announcement of the election result, our correspondent says.
The new chief executive – nominated by Abdullah – will be side-by-side with the president when he is inaugurated.
Abdullah will be able to appoint senior positions on terms of “parity” with Ghani. The agreement says “the two teams will be equally represented at the leadership level”.
However, our correspondent says there will not be a one-for-one handout of jobs further down and that could lead to arguments.
The agreement calls for a spirit of partnership. But after a bitter election campaign and months of wrangling, the stability of this government cannot be guaranteed, he adds.
Earlier, Abdullah told the BBC that he accepted Mr Ghani should be leader.
A spokesman for Ghani said that there was no longer any dispute between the two sides.
One of the new president’s first tasks is widely expected to be signing a bilateral security agreement with the US.
The deal will allow a small force of soldiers to remain beyond 2014 to train Afghan security forces.
President Karzai refused to sign the security agreement, which is linked to the continuation of aid needed to pay Afghan civil servants, teachers and soldiers.