The U.S. military hasn’t suffered a fatality in Afghanistan since February 2020—that is, for 16 months. So the tangible costs of staying in the country, at the reduced troop levels that had become the new normal, would have been relatively low.

Meantime, the intangible risks of leaving, on humanitarian as well as strategic grounds, are relatively high.

So what is it about the mood of America today that is compelling a departure?

The question is largely rhetorical at this point, because the departure is happening. The Pentagon said last week that the withdrawal will be completed by the end of August, a few weeks earlier than expected when President Biden said forces would be out by the 20th anniversary of the Sept. 11, 2001, terrorist attacks that prompted the move into Afghanistan in the first place.

The departure impulse is bipartisan. Former President Donald Trump announced while he was still in office that all forces would be gone this year; Mr. Biden is following through.

This is happening even though the American presence has been reduced to a few thousand troops, largely operating in non-combat situations. They weren’t “winning” the struggle against Taliban extremists, but they were creating some semblance of stability and keeping the Taliban and its version of anti-Western Islamism out of power.

Juxtaposed against that picture are the very visible risks of departure. Those risks start with the high likelihood of an eventual collapse of a pro-American government and its Afghan army, and a Taliban takeover. That could open the door Afghanistan to again serve as a safe haven and operations center for Islamic extremists, including al Qaeda and Islamic State, still intent on harming the U.S.

A return to Taliban power also likely would produce a humanitarian disaster, including revenge against Afghans who supported the U.S. and those who oppose radical Islamic rule, and the rollback of significant gains made by Afghan women.

“To the extent the U.S. remains an advocate for freedom and democracy, a Taliban takeover would represent a dramatic setback, especially for women and girls,” says former Defense Secretary Robert Gates.

There are strategic costs as well. An American presence in Afghanistan, including at the large air base at Bagram, has given pause to both Iran to the west and China to the east. A significant American presence in that strategic spot provided at least a bit of a check on Iranian aggression and Chinese expansionism. There now is at least some risk of the Taliban becoming a client of an increasingly ambitious Chinese government (though China’s hostility to its own Muslim population may reduce that risk).

Moreover, American bases in Afghanistan also provided a platform for intelligence services to better keep a watch on Iranian activities. That platform is disappearing.

A departure from Afghanistan also spells an end to much of the help the U.S. was getting from allies in keeping the country stable. To the extent the U.S. still can keep an eye on what’s happening on the ground, and strike out at extremist threats that develop, it will have to do it at long range, from bases and ships far away. The U.S. has the ability to do that; its allies don’t. So keeping threats at bay becomes much more of an American-only proposition.

So why is America, which has been happy to continue a significant military presence in Europe, Japan and South Korea for decades to preserve stability, not willing to do the same in Afghanistan? The answers say a lot about our national character, and the particular national mood of the times.

First, in sheer dollar terms, the budgetary cost of staying in Afghanistan still is significant, and federal deficits are soaring. In human terms, there were no guarantees that the toll on American troops could remain so low. Taliban attacks on American soldiers have been down because of a shaky peace deal struck last year that presaged an American withdrawal; without a withdrawal, attacks likely would start going back up. Unlike in Europe, Japan and South Korea, a significant part of Afghan society doesn’t want American troops around.

Beyond that, Americans don’t see themselves as occupiers. They prefer to see themselves as liberators—as people who end occupations—so a permanent presence amid at least some local resistance rubs against the American way.

The American urge is to “win” any contest, military or otherwise, not to keep playing at it. A military win in Afghanistan didn’t merely prove elusive; most analysts concluded long ago it wasn’t even possible. Any “win” in Afghanistan was going to be political, not military.

In any case, America is in an America-first mood right now.

So, having learned the cost of going into Afghanistan, Americans now will learn the cost of leaving. And there will be one.

Write to Gerald F. Seib at jerry.seib@wsj.com