On Javier Mackey's second deployment to Afghanistan, one of his friends was shot in an ambush and bled to death in his arms. He saw high-ranking Afghan officers selling off equipment for personal gain and Afghan troops running away during firefights. And he started wondering what the United States could really achieve by sending thousands of troops to a distant land that seemed to have never known peace. That was in 2008.

Mackey, an Army Special Forces soldier, deployed there five more times, was shot twice, and, he said, grew more cynical on each trip, until he decided the only sensible thing for the U.S. to do was cut its losses and leave.

Even so, seeing the swift and chaotic collapse of the Afghan government in recent days hit him with the intensity of a bomb blast.

"It's pain — pain I thought I had gotten used to," said Mackey, who retired as a sergeant first class in 2018 and now lives in Florida. "I sacrificed a lot, I saw death every year. And the guys I served with, we knew it would probably come to an end like this. But to see it end in chaos, it makes us angry. After everything we gave, I just wish there had been a way to leave with honor."

In the 20 years that the U.S. military was in Afghanistan, more than 775,000 U.S. troops deployed there, to citylike air bases and sandbag outposts on lonely mountaintops. As the Taliban swept into Kabul on Sunday, wiping away any gains made, veterans said in interviews that they watched with a roiling mix of sadness, rage and relief. Some were thankful that America's involvement in the country seemed to have ended, but were also dismayed that hard-won progress was squandered. Others were fearful for Afghan friends left behind.

In interviews, text messages and on Facebook, men and women who collectively spent decades in Afghanistan said they were angry that despite a drawdown that has spanned years, the United States could not manage to exit the country with more dignity.

The anguish can be especially raw because veterans often worked side by side with Afghans during the years of attempts at nation-building, and now in that nation's collapse they see the individual faces of friends who have been enveloped by the anarchy.

"My heart breaks for the Afghan people," said Ginger Wallace, a retired Air Force colonel who in 2012 oversaw a program that retrained low-level Taliban fighters to clear land mines and work in other jobs that offered an alternative to combat.

At the time, she thought that efforts to stabilize Afghanistan were succeeding, and that U.S. troops would one day leave the country a better place. But her optimism slowly wore down as the Taliban gained ground.

"It's heartbreaking, absolutely. I hate to see it end like this, but you don't know what else we could have done," she said from her home in Louisville, Kentucky. "Do we have an expectation that U.S. service members should stay and fight the Taliban when the Afghan army won't?"

Wallace met her wife, Janet Holliday, while deployed in Afghanistan. The two normally watch the news each morning, but Monday, as scenes of mayhem unfolded at the airport in Kabul, Holliday, a retired Army colonel, switched to the Food Channel.

"It was too hard to watch," Holliday said, excusing herself as she became upset. "I just can't help thinking about what a waste it is. I can't allow myself to think about how after all that blood and treasure, it ends like this."

More than with other wars in the nation's history, Americans have been mostly insulated from the fighting in Afghanistan. There was no draft or mass mobilization. Less than 1% of the nation served and a disproportionate number of troops came from rural counties in the South and West, far from the seats of power.

But veterans have said in interviews over the years that they were cleareyed about the challenges posed by the war, perhaps more so than the rest of the nation. They saw firsthand the deeply ingrained traditional cultures, tribal allegiances and endemic corruption that continually hobbled U.S. efforts.

Mackey agreed with President Joe Biden's decision to withdraw, but thought the way it was done was slapdash and unprofessional.

"We train to have contingencies. The way it was handled was just irresponsible," Mackey said. "We didn't want to have another Vietnam, we wanted to do better."

Jake Wood was a 25-year-old Marine sniper deployed to a forgotten corner of Afghanistan in 2008 when he started to see how much daylight there was between the optimistic pronouncements of top U.S. leaders and the reality of serving with Afghans on the ground.

Villagers in the district center of Sangin, where he manned an outpost, seemed to have little allegiance to the Afghan government in Kabul or the U.S. vision of democracy.

"We had no idea what our mission was, even back then," said Wood, who now runs the nationwide veteran volunteering network Team Rubicon. "Were we trying to defeat the Taliban? Were we nation-building? I don't think we knew."

The Afghans he served with seemed to accept the uncertainty with a weary fatalism foreign to young Marines. At one point over small cups of tea, he said, he spoke with a young Afghan he served with who said Afghanistan only knows war, and when the U.S. war ended, another would come.

"He told me that maybe the Americans would come back," Wood said. Then he recalled the Afghan saying, "But if you do, I can't tell you if we'll be friends or enemies."

Wood said the veterans he has been in touch with feel a mix of sadness and fury watching the fall of Kabul: sadness that the folly that seemed so obvious in the ranks took years and thousands of lives for top leaders to accept; fury that the result of that ignorance and hubris was playing out on cable television in a way that would tarnish the reputation of the nation and the hundreds of thousands of troops who fought.

"We already knew we were losing the war," he said. "But now we are losing it live on TV in front of the rest of the world. That's what's so hard."

This article originally appeared in The New York Times.