The Biden administration, which kept Khalilzad in his job for another nine months, was expected to announce the resignation later Monday.
"I decided that now is the right time," Khalilzad said in a resignation letter to Secretary of State Antony Blinken, "at a juncture when we are entering a new phase in our Afghanistan policy."
Its parting of ways with one of the most senior Trump appointees remaining in the government had been widely seen as only a matter of time, although it was unclear whether he was asked to leave.
In a brief statement, Blinken thanked Khalilzad for his service and said that Tom West, Khalilzad's deputy, would take over as the administration's special representative.
In the wake of the frenzied U.S. exit from Afghanistan, Khalilzad has been the target of extensive criticism - including from the current administration - for an agreement seen as giving too much and gaining little.
But to the Afghan-born envoy, it was not a faulty agreement that led to August's Taliban takeover of Afghanistan, but Washington's decision - under both Trump and President Joe Biden - to press ahead with the withdrawal despite the Taliban's failure to comply with most of its terms, according to people familiar with Khalilzad's views who spoke on the condition of anonymity to discuss private conversations.
"The Talibs committed to not allow terrorist groups, including Al Qaida, [to] plan or carry out attacks against the security of the United States and our allies," Khalilzad wrote in his letter, a copy of which was obtained by The Washington Post. "They further agreed not to allow terrorists to recruit, train, or fundraise in the territories they controlled. They also agreed to negotiate directly with the existing Afghan government for a power sharing agreement and a comprehensive and permanent ceasefire."
"As part of this package," he wrote, "we agreed to withdraw our forces in phases over a 14-month period if the Taliban implemented their commitments."
As part of the deal, signed on Feb. 29, 2020, by Khalilzad and senior Taliban official Abdul Ghani Baradar - now deputy prime minister in the interim Taliban government - the militants agreed not to attack U.S. troops if they kept to the timeline, which called for full withdrawal of "all foreign forces" by May 1, 2021.
Although Biden extended the deadline to Sept. 11, and completed the withdrawal on Aug. 31, that was the only aspect of the agreement that was fully realized.
U.S. intelligence has assessed that the Taliban and al-Qaeda in Afghanistan retain strong bonds. Negotiations with the Afghan government, which began in September 2020, never gained any traction, a situation that Khalilzad, and both administrations, attributed in large part to foot-dragging by Ashraf Ghani, the former U.S.-backed president.
"The political arrangement between the Afghan government and the Taliban did not go forward as envisaged," Khalilzad wrote. "The reasons for this are too complex and I will share my thoughts in the coming days and weeks, after leaving government service."
Asking "what should the U.S. objective and strategy be in this new phase," Khalilzad said he planned "to contribute to the discussion and debate about not only what happened but what should be done next."
Whether under Biden or Trump, no one appeared more qualified for the job of pushing Afghanistan toward peace and negotiating with both the Taliban and the Afghan government than Khalilzad.
Born and raised in Afghanistan, he had gone to school with Ghani and the two traveled together to the United States as young students. As a Columbia University professor, he worked with the Jimmy Carter administration in the early days of U.S. covert support for Afghan mujahideen fighting against the Soviet Union's occupation of Afghanistan.
He joined the State Department under the Ronald Reagan administration, again advising on policy toward Afghanistan. After the Soviet withdrawal, Khalilzad served under President George H.W. Bush as deputy undersecretary of defense for policy planning.
After work in think tanks and the energy sector, he served as U.S. ambassador to Afghanistan, Iraq and the United Nations under the George W. Bush administration. He spent the Obama administration years out of government.
Trump came to office vowing to "fight to win" in Afghanistan, after which he said the United States would withdraw completely.
It wasn't until 2018 - as the Taliban had grown stronger rather than weaker on the ground, and withdrawal seemed further away - that Trump decided to negotiate with the militants and Khalilzad was asked to return to government.
Talks between him and Baradar began in November 2018, with the deal finally announced 16 months later.
After Biden's inauguration, the new administration decided to keep Khalilzad in place while it reviewed Afghanistan policy. The envoy continued to try to push the Afghan government and the Taliban toward an agreement, to no avail.
Once the new withdrawal date had been announced, Khalilzad continued to negotiate the U.S. departure with the militants, and worked with regional governments in an unsuccessful effort to secure basing agreements for the United States to continue counterterrorism operations in Afghanistan without troops on the ground there.
Khalilzad also kept up the most direct line of contact with senior Taliban officials during the fraught U.S. evacuation effort.