DOHA (BLOOMBERG) - The weeks leading up to Kabul's collapse saw a flurry of diplomatic activity by the United States and its allies in Qatar aimed at heading off exactly the chaotic scenes in the Afghan capital that have so horrified the world and put Mr Joe Biden's presidency on the defensive.
Among those efforts was a tantalising agreement that could have guaranteed calm.
Afghan and Taleban negotiators tentatively reached a deal in which all sides would declare a two-week ceasefire in exchange for President Ashraf Ghani's resignation and the start of talks on setting up a transitional government, according to two people familiar with the matter, who asked not to be identified discussing private deliberations.
That opportunity, which has not been previously reported, was lost when Mr Ghani fled the country, according to the people.
Mr Ghani's decision to leave Afghanistan - he said he did so to avoid a bloodbath - surprised his negotiating team in Doha, American diplomats and even his chief of staff and other top aides, said the people.
Under the terms of the tentative agreement, the ceasefire would have led the way for former president Hamid Karzai and other current and former officials to broker some sort of power-sharing deal with the militant group ousted from power nearly two decades ago. Mr Karzai has remained in Kabul after the Taleban takeover.
That scuttled agreement in Qatar underscores just how quickly the ground has shifted in Kabul in recent days and how swift and surprising the Taleban takeover has been.
With the Taleban now controlling nearly every population centre in the country and Afghanistan's government in a state of collapse, the challenge is finding a way to compel the Taleban to share any power at all.
"For all intents and purposes, the peace talks in Doha are over," said Mr Anish Goel, senior fellow at New America and a former White House senior director for South Asia under former president Barack Obama.
"The Taleban were never negotiating in good faith and there is no reason for them to start now. They have all the power in Afghanistan and clearly don't want to share it," he said.
Even the Taleban seemed surprised with their rapid gains, with deputy leader Mullah Abdul Ghani Baradar - the militant group's chief negotiator in Qatar - saying on Monday (Aug 16) that the swiftness of the Taleban advance was unexpected.
"We shouldn't embrace arrogance," Mr Baradar said. "Now is the time when we will be tested on how we serve and secure our people, and ensure their good life and future to the best of our ability."
The US State Department declined immediate comment.
A newly established coordination council established by Mr Karzai and Mr Abdullah Abdullah, the head of the High Council for National Reconciliation, could not be reached for comment.
The tentative agreement was hammered out between the Taleban and Afghan government negotiators who have been meeting in Doha for months as part of efforts to come up with a peaceful transition of power after former president Donald Trump cut a deal with the Taleban for US troops to withdraw by May. Mr Biden extended that deadline to September.
The top US envoy for those talks, Ambassador Zalmay Khalilzad, is in Doha now trying to come up with a new path forward to ensure peace holds in the Afghan capital now that the Taleban have largely seized control.
The focus, the people said, is on a smooth and peaceful transition to a new government that includes elements of all Afghan society, not just the Taleban.
But now it is not clear if any talks will take place.
"The so-called 'peace talks' were a sham, and the Taleban were never interested in negotiating a peaceful power-sharing settlement," said Ms Lisa Curtis, Mr Trump's former National Security Council senior director for South-east Asia.
"This was largely President Ghani's fault. However, the way in which the US handled peace talks in Doha also contributed to undermining Ghani."