The signing comes after months of wrangling following presidential elections in April and June.
A deal to form a government of national unity in Afghanistan has been signed at a ceremony in Kabul.
Under the deal, Ashraf Ghani becomes president while runner-up Abdullah Abdullah nominates a CEO with powers similar to those of prime minister.
Later, the election commission declared Mr Ghani as winner of the bitterly fought poll.
"The Independent Election Commission declares Ashraf Ghani as the president, and thus announces the end of election process," commission chief Ahmad Yousaf Nuristani said without declaring the number of votes for each candidate or the turnout figures.
Both sides had accused the other of fraud following the election and the months of uncertainty have damaged the economy and worsened insecurity.
Mr Ghani and Mr Abdullah signed the agreement at a televised 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 Mr 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.
A deal to form a government of national unity in Afghanistan has been signed at a ceremony in Kabul.
Under the deal, Ashraf Ghani becomes president while runner-up Abdullah Abdullah nominates a CEO with powers similar to those of prime minister.
Later, the election commission declared Mr Ghani as winner of the bitterly fought poll.
"The Independent Election Commission declares Ashraf Ghani as the president, and thus announces the end of election process," commission chief Ahmad Yousaf Nuristani said without declaring the number of votes for each candidate or the turnout figures.
Both sides had accused the other of fraud following the election and the months of uncertainty have damaged the economy and worsened insecurity.
Mr Ghani and Mr Abdullah signed the agreement at a televised 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 Mr 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.