Afghanistan's rival presidential candidates signed a deal to share power in a unity government, capping months of turmoil over a disputed election that destabilised the nation at a crucial time as foreign troops prepare to leave.

Ashraf Ghani, a former finance minister who will be named president under the deal reached on Saturday night, embraced rival Abdullah Abdullah after they signed the agreement on Sunday.

The ceremony at the presidential palace in Kabul, still occupied by outgoing leader Hamid Karzai, was broadcast live on television.

Karzai spokesman Aimal Faizi said Ghani is expected to be sworn in as president within a week.

He said one of Ghani's first acts would be to sign a long-delayed bilateral security agreement with the United States to allow a small force of foreign troops to remain in Afghanistan after 2014.

The deal was signed on the same day that the final results from a recount are to be announced.

Live Box 201491152731407786

Preliminary results released in July showed Ghani ahead of ex-foreign minister Abdullah with 56 percent of the vote.

The early results prompted street protests from supporters of Abdullah, who charged massive fraud and said he was the rightful winner.

Final results have been delayed for weeks by a UN-monitored audit of all eight million ballots cast in the June 14 runoff vote between Ghani and Abdullah, the top finishers of the first round in April.

Reporting from Kabul, Al Jazeera's Jennifer Glasse said the new government will face a number of challenges.

"Afghanistan remains heavily dependent on international aid, corruption is widespread and the extended election process has left Afghans suspicious of politicians," she said. "They want a government which will unite them, and help get the economy back on its feet."

Source: Al Jazeera and agencies