Human beings sometimes crack, as the U.S. Army staff sergeant did at 3 a.m. Sunday when he allegedly left his base outside Kandahar and began killing Afghan civilians in an apparent spasm of rage and frustration. But nations shouldn’t crack. Even under the stress of a war that some days seems to be going horribly wrong, nations should move carefully so they don’t leave more chaos and dead bodies in their wake.

Some of the recent events in Afghanistan show the American military mission at its worst: urinating on enemy dead; accidentally burning Korans; a crazed soldier allegedly massacring civilians. We can say that most U.S. troops did nothing of the sort and that such disruptions are rare. But this doesn’t change the reality that, in these moments, we see how war can degrade decent men and nations.

The question for policymakers isn’t the nature of war but how to end it. And here, the gut reactions of this week are likely to be misleading — in the sense that they could prompt hasty decisions that bring more loss of civilian life. A retreat under fire is dangerous in any case, but especially a pell-mell retreat that abandons previous strategies for withdrawal.

That’s why Newt Gingrich’s sudden conclusion that the war isn’t “doable” is especially unfortunate. What did he think was possible here? If he was looking to force the Taliban to a USS Missouri-style surrender, he’s in the wrong century.

President Obama has already said that he intends to “responsibly wind down this war,” as he put it Tuesday. He has agreed with NATO allies to transfer the lead combat role to the Afghans by the middle of next year and withdraw most foreign troops by the end of 2014. It’s a plan framed by both the United States and its most important partners. It’s not something for Americans to discard under duress because they’re angry, aggrieved or even ashamed by recent events.

The U.S. strategy has been to shape the Afghanistan we will leave behind after 2014. Almost certainly, that country will be a mess. But as we discovered in Iraq, there’s a difference between the out-of-control, homicidal mess of 2006 and the more controlled mess of 2011, when the last U.S. troops finally departed. The civil war that so many feared hasn’t yet happened.

As in Iraq, the United States hopes to create conditions that can contain the disorder. That may sound like a fool’s errand, given Afghanistan’s bloody history, but it’s based on some sensible ideas: Build a good enough Afghan army to hold Kabul and maintain contact with the provinces; negotiate political power-sharing with the Taliban that can avert civil war; and work with Afghanistan’s neighbors to build a firewall that can keep the inevitable violence there from destabilizing the region.

That’s a hard strategy to pull off — and even harder after Sunday’s massacre — but not an impossible one. It still looks better than the alternatives, which are guaranteed versions of civil war, partition or both. The administration also hopes to maintain a counterterrorism force in Afghanistan that can prevent al-Qaeda from regaining a safe haven. That’s a platform worth fighting for, although the Iraq example isn’t encouraging about the likelihood of a residual troop presence.

When one thinks about how to end the war in Afghanistan, it’s useful to consider the culture of our adversaries. The Pashtuns are good at starting wars, but they also have rituals for stopping them. The core idea is what the Pashtuns call “nanawatay,” in which one of the combatants figuratively goes into the house of the other to settle the feud. A stable settlement is one with the balance of honor that Obama often describes with the phrase “mutual interest and mutual respect.”

Obama’s special representative for the region, Marc Grossman, has been holding secret talks with the Taliban for more than a year. Until Sunday, that process seemed to be going in the right direction, toward the Taliban opening an office in Qatar and beginning real peace talks. This track will undoubtedly be harder after Sunday’s rampage, which has given the Taliban’s hard-liners new arguments for resisting negotiations.

Grossman has also been talking with neighboring countries about building a structure to keep a future Afghanistan from disintegrating. This regional framework still seems possible, even if the talks with the Taliban prove fruitless.

The diplomatic options are uncertain, like U.S. military operations on the ground. But they are part of a withdrawal strategy that looks well-reasoned even after Sunday’s disaster in Kandahar.