The agreement between Ashraf Ghani and Abdullah Abdullah came at the end of two days of frantic negotiations brokered by US Secretary of State John Kerry.
The deadlock over the run-off vote to choose a successor to outgoing President Hamid Karzai plunged Afghanistan into political crisis and dented US hopes of a smooth transfer of power as Washington seeks to withdraw all its troops by late 2016.
But almost 48 hours after he flew into the Afghan capital on a hastily-arranged mediation trip, Kerry announced the breakthrough.
"Both candidates have committed to participate in and stand by the results of the largest possible audit. Every single ballot that was cast will be audited, all eight million," Kerry told reporters.
"The winner will serve as president and will immediately form a government of national unity."
Ghani's campaign had embraced the UN plan but Abdullah's team remained sceptical, arguing the proposal failed to address all their concerns.
Kerry said the full audit would be carried out in Kabul and begin within 24 hours, with NATO and Afghan forces transporting ballot boxes to the capital.
The chief US diplomat said the audit would be "conducted in accordance with the highest international standards" and would take "a number of weeks".
The head of the UN mission in Afghanistan, Jan Kubis, appealed for observers to oversee the audit.
"To make it (the audit) a success, I would like to appeal to international observer organisations... Send as quickly as possible teams to support this process," Kubis said.
Yesterday Kerry stressed that results released on Monday showing Ghani in the lead -- with some 56 per cent of the vote, ahead of Abdullah on 44 percent -- were only "preliminary".
