The world is still processing the sudden trauma of the U.S. withdrawal from Afghanistan; it will take years for its full consequences to be known and understood. Nevertheless, it is not too soon to consider the way forward for U.S. foreign policy. President Biden himself has defined the stakes. Early in his administration, he depicted the global future as a long contest between leaders such as Vladimir Putin of Russia and Xi Jinping of China, who argue “autocracy is the best way forward,” and the United States and its allies who think that “democracy will and must prevail.”

We agree with that strategic vision. It is doubly urgent given that, perhaps uniquely in recent history, Russia and China are not only strong and averse to the United States but also often act in concert.

Unfortunately, Mr. Biden’s decision to pull U.S. and allied forces out of Afghanistan unconditionally, and cede the country to the theocratic Taliban, is hard to reconcile with his vision. The Biden administration does not see things that way, of course: The president argues that Afghanistan was absorbing resources better spent on great power competition. But the timing and the manner of the withdrawal, including Mr. Biden’s disparagement and abandonment of erstwhile Afghan allies — flawed as they were — sent a problematic message. Onlookers abroad might draw two conclusions: that there are limits to U.S. staying power, and that the United States deems not all people equally deserving or capable of self-rule.

In the aftermath of the disaster in Kabul, Mr. Biden insisted — forcefully — that henceforth, this country will act only in its “national interest” and will cease trying to democratize other countries through military force. This is a straw man. The United States tried to establish a stable democracy in Afghanistan because, having invaded in the national interest — to oust the Taliban and the al-Qaeda terrorists it harbored — it would have been irresponsible and self-defeating to leave a power vacuum behind.

The U.S. national interest and the promotion of democracy, or at least political stability, abroad are not so easily separated, any more than American interests have ever been determined without reference to American values. What else explains the Biden administration’s current effort to shore up the elected government of Ukraine, another state where corruption is corrosive — but which, in strategic terms, stands as a bulwark against the Russian autocracy’s encroachment on democratic Europe?

To outcompete autocracy, Mr. Biden said March 25, “We’ve got to prove democracy works.” That is true, especially as it applies to the president’s domestic agenda on economic revitalization and voting rights. The United States must get its own house in order. Yet China’s and Russia’s global comebacks have rested more on their willingness to wield hard power than on the example of their political and social systems. They provide political, economic and military support to regimes they back, such as Cambodia, Syria or Venezuela, and they have shown the brutal and corrupt regimes that rule those states that they will remain for the long haul. The rest of Mr. Biden’s presidency must be devoted to showing the world’s democracies, both established and embattled, that the United States stands beside them just as firmly.