The two rival candidates in Afghanistan's presidential election have agreed to abide by the results of a UN-supervised recount of the entire poll to settle their dispute over the outcome, US Secretary of State John Kerry said after talks with both men.

The recount was scheduled to begin within 24 hours, but was likely to take several weeks, meaning that a presidential inauguration due on 2 August will be postponed.

The deadlock over the 14 June election run-off between the leading contenders, Abdullah Abdullah and Ashraf Ghani, has raised concerns about a smooth transition of power in Afghanistan just as US-led troops are leaving.

"Both candidates have committed to participate in and abide by the results of the largest and most comprehensive audit. Every single ballot that was cast will be audited," Mr Kerry told a joint news conference with both candidates, held just before midnight after talks dragged for two days.

"This is the strongest possible signal by both candidates ofthe desire to restore legitimacy to the process."

Washington hopes to settle the dispute quickly so it can sign a crucial security pact with Afghanistan allowing a small contingent of US troops to stay in the country beyond this year.

Unlike incumbent Hamid Karzai, both Mr Abdullah and Mr Ghani have promised to sign the deal promptly, but the protracted standoff over the vote has delayed the process.

Mr Ghani and Mr Abdullah have been locked in an acrimonious dispute since the 14 June run-off, both effectively claiming victory and Mr Abdullah refusing to accept the outcome.