A comparison of the two wars has not been fashionable for many years now, with scholars pointing out that superficial similarities were greatly outweighed by the differences. Vietnam took place at the height of the Cold War, with the superpowers on opposite sides. Vietnam and Afghanistan are dramatically different in culture, geography and history. Even the scale of the two wars was vastly different: Half a million American troops went to Vietnam at its height, compared with a maximum of 100,000 to Afghanistan, now whittled down to 14,000; more than 58,000 Americans died in Vietnam, fewer than 3,000 in Afghanistan.

Yet a significant number of the American ambassadors and military leaders who served in Afghanistan are worried about the similarities. Karl Eikenberry, the American military commander in Afghanistan from 2005 to 2007, and then the American ambassador from 2009 to 2011, said that in both countries it was a challenge to develop a national force committed to protecting the weak and corrupt central government. And in both places, the host country’s forces, many of them trained by the United States, “were further undermined because they constantly doubted the long-term support of the U.S.,” said Mr. Eikenberry , who is now a professor at Stanford.

Mr. Crocker is among those who worry that the Trump administration just wants out of Afghanistan and is willing to sacrifice gains that have been made, particularly on behalf of women. A rushed deal could put the Taliban in a position to eventually take over, as happened in Vietnam when the United States withdrew its troops even though the North Vietnamese did not keep their promise to do the same.

“I imagine we and the Afghans have killed most of the slow and stupid” Taliban fighters, Mr. Crocker said. “The ones who are still in the Taliban after 18 years are now tough, committed, and I can’t imagine them signing on to any meaningful compromise. They’ll just talk compromise.”

Not all recent ambassadors are prone to drawing parallels to Vietnam. James Cunningham, who was ambassador from 2012 through 2014 and is now a senior fellow at the Atlantic Council in Washington, said fear that the United States will cut and run is “definitely a concern for a lot of people back here, and for the Afghans I know. And there may be some people who want that to happen.” But he said the analogy wasn’t accurate. In America, he said, “there’s a lot of sympathy for the Afghans and what they’re trying to do. This doesn’t have to be a recipe for rushing to the exits and I hope it won’t be.”