Afghan president Ashraf Ghani’s decision to flee the country last month scuppered a last-minute deal with the Taliban designed to keep Kabul out of the Islamists’ hands and negotiate a political transition, the US diplomat in charge of talks with the Taliban has said.

In his first interview since the US exit from Afghanistan, Zalmay Khalilzad, who was appointed by Donald Trump in 2018 to lead talks with the Islamist insurgents, said he had secured a two-week grace period hours before the fall of Kabul.

Under the plan, Ghani was to remain in his post until a settlement on a future government was reached in Qatar, even as the Taliban stood at Kabul’s doors. But the security vacuum left by Ghani’s escape on August 15 prompted the Islamists to march into the Afghan capital that day, Khalilzad said. This in turn precipitated a chaotic evacuation of civilians and troops and effectively ended the talks in Doha.

“Even at the end, we had an agreement with the Talibs for [them] not to enter Kabul,” Khalilzad told the Financial Times. He had no inkling “at all” that Ghani was intending to flee, he said.

The US envoy’s comments shed some light on the collapse of the Afghan government in its final hours and the dismay within the US administration when Kabul fell to the Taliban. They echo secretary of state Antony Blinken who told US lawmakers this week he had received assurances from Ghani on the eve of his escape that the Afghan president was on board with Washington’s plan.

Kabul security forces disbanded at the news of Ghani’s disappearance, Khalilzad said. “There were questions of law and order in Kabul after Ghani fled . . . The Talibs [then] . . . say: ‘Are you going to take responsibility for security of Kabul now? . . . And then you know what happened, we weren’t going to take responsibility,” he said, adding he attended a pre-arranged meeting that day with US regional military commander General Frank McKenzie and senior Taliban leaders in Doha.

Khalilzad rejected claims of a tacit or explicit arrangement allowing the Islamists into the presidential palace on August 15. “We didn’t give them any sort of green light or anything of that kind. What we said is what the mission of the US forces was,” he said, referring to the airport evacuation.

The US envoy to Afghanistan first discussed the standstill deal with the Kabul government on August 12 and reached an accord with the Islamists two days later to safeguard the city’s integrity, according to US officials. Ghani, however, was not likely to be part of any future government because his resignation was a precondition set by the Taliban. By August 13, the Islamists were encircling Kabul after seizing control of most of the country.

Ghani could not be reached for comment. In a video posted on Facebook from the United Arab Emirates on Aug 18, Ghani said he fled because his life was in danger and to “prevent bloodshed” in Kabul as the Taliban descended on the capital. He said he left with one change of clothes and described allegations that he absconded with looted cash as “baseless lies”. On Twitter last week he said his palace security had advised him that “to remain risked setting off the same horrific street-to-street fighting the city had suffered during the civil war of the 1990s”.

Khalilzad, a 70-year-old Republican, has come under fire for his handling of the Taliban in the past three years and the deal he brokered in 2020 under Trump setting the terms of the US withdrawal. Critics say this accord squandered Washington’s leverage in negotiations, undercut the elected government in Kabul and helped legitimise the Islamist insurgency.

US president Joe Biden criticised the 2020 pact but retained the Afghan-born diplomat as top US envoy to Afghanistan — a decision that Khalilzad said surprised him “at one level”. In a reflection of Kabul’s resentment at the deal he negotiated and expectations Biden would appoint someone else, Ghani at one point refused to meet him.

“I was prepared, obviously, to leave,” said Khalilzad.

A former US ambassador to Afghanistan who has worked on the region for four decades, he blamed those before him for the limitations of his 2020 deal. He suggested successive US administrations had gradually reduced their demands as the Taliban made military gains. His 2018 appointment “was the result of what had not gone right,” he said.

“[People] are looking for a scapegoat of some kind,” he added. “I’m sure I could have done better — people would expect me to say that. But when I reflect I did my very best that I could, given the cards I was dealt with in the circumstances, the fundamentals.”

Asked whether he considered resigning, he said he always had a letter ready that he kept at home “because here [in state department] somebody might take it”.

In the hour-long interview, Khalilzad also denied claims from the CIA’s former regional counter-terrorism chief that he was “dabbling” and had overpromised in an effort to become Trump’s secretary of state as “total nonsense”.

The responsibility for the messy ending of America’s longest war lay largely with the Afghans, he said. “[T]he fact that they didn’t [negotiate peace] or one side disintegrated, that’s not the responsibility of the United States. It’s not my responsibility.”

Khalilzad said he nevertheless mourned the failure to deliver a political settlement with the Taliban years earlier. “There will be a lot of soul searching,” he said.

Additional reporting by Amy Kazmin in Delhi