KABUL - He was only on the ground for 48 hours, but America's top diplomat John Kerry may well have helped prevent Afghanistan from sliding into another bloody ethnic war.
The helicopters were waiting for the US Secretary of State when he arrived in Kabul from Beijing early Friday on a last-minute mission to broker an end to a tense political impasse.
Some 48 hours later they flew him back over the darkened city streets from the fortress-like US embassy compound to his plane - a deal triumphantly in his hand.
Few had believed it possible that Kerry could bring together two presidential rivals bitterly at odds over disputed elections, and help avert fears of ethnic violence in a country ravaged by decades of war.
But the indefatigable 70-year-old dropped a political bombshell when he announced that rivals Abdullah Abdullah and Ashraf Ghani had agreed that every one of the eight million votes cast in their June run-off poll would be audited.
Just days earlier the two men were barely speaking, as Abdullah vehemently accused Ghani of stealing victory by stuffing the ballots.
But standing next to each other with Kerry late on Saturday before the world's cameras, they clasped hands, smiling, and raised them in the air.
With that single dramatic show of unity, Kerry may well have helped guide Afghanistan's young democracy away from a return to the bloody ethnic civil war of the 1990s.
The announcement followed two days of marathon meetings, with Kerry and his staff shuttling between the two candidates and their teams in the embassy.
He also met for hours one-on-one with each candidate.
With Kerry due in Austria for talks on a Iran nuclear agreement, Saturday's window for a deal was closing rapidly.
"It wasn't until the 11th hour... that we had a full agreement," a senior US official who took part in the negotiations told journalists.
The talks had focused on the best mechanism for auditing the poll results.
A second track sought to persuade the feuding rivals to meet to discuss their differences and clear the way towards a national unity government.
'Pact prevented chaos'
Afghan analyst Younus Fakour said the agreement had "prevented a disaster in Afghanistan, it prevented the creation of a parallel government, it prevented chaos" - and the national unity government element was crucial.
"Before, the candidates were afraid that if one wins, the other will be left out. But with this they are sure they will be part of the next government," he told AFP.
By midday Saturday it became clear that given doubts over a UN proposal to audit votes from around 35 per cent of polling stations, it made more sense to work towards an unprecedented review of all ballots cast.
"While it's more resource-intensive, while it's time-intensive, a full audit stands to more significantly improve the credibility of the outcome just because it's more extensive," a second US official said.
As reporters awaiting a press conference at UN mission headquarters broke the Ramadan fast with a hastily arranged "iftar" of take-away lamb, rice, bread and dates, Kerry persuaded the two men to meet face-to-face.
Ghani, a former World Bank economist, was asked to join talks with Abdullah as they also hammered out a structure for a national unity government.
"When Dr Ghani walked in, the two approached each other and immediately embraced and there was clearly a degree of affection between the two," the first US official said.
"For those of us who had sat through these meetings over 48 hours it was a welcome sign, a signal that actually here is something that may stick because it's going to require the personalities involved to be committed to it." The dispute had raised fears of an ethnic split, as Abdullah draws support from Tajiks and other northern groups while Ghani is backed by Pashtun tribes of the south and east.
'You deliver miracles'
Both US officials praised the role of the United Nations which has been working intensively for weeks to break the deadlock, and which flew in its chief electoral official for the negotiations.
The US will now support calls from the head of the UN Assistance Mission in Afghanistan, Jan Kubis, for additional resources and manpower to help audit all ballots in coming weeks.
"You deliver miracles," Kubis told Kerry, as they got the final seal of approval from outgoing President Hamid Karzai.
"Because what we witnessed today was not just a topmost diplomatic achievement, it was close to a miracle." Kate Clark of the Afghan Analysts' Network hailed the US role and said the deal's "strong international underpinning" gave cause for optimism.
While it still remains unclear how the agreement will play out, one Afghan official emailed a member of Kerry's team voicing heartfelt thanks and adding that "most Afghans will sleep more peacefully tonight".