Two decades after political theorists in the United States and Europe celebrated a “post-national constellation” and “cosmopolitan democracy,” politics is increasingly shaped by explicitly nationalist appeals. The avatar of this new nationalism is Donald Trump, who urged the world in his United Nations speech last month “to reject the ideology of globalism and accept the ideology of patriotism.”

In Mr. Trump’s version of nationalism, Muslims and Mexican-Americans are stigmatized, and African-American football players who protest racial injustice by kneeling during the national anthem are denounced. Some of his applications of “America first” — repudiating the Paris climate agreement or abandoning the Iran nuclear deal — may not even prove to be in the national interest.

But these failings should not lead you to dismiss the value of nationalism, which, by itself, is neither good nor evil, liberal nor conservative. The perception of a common national identity is essential to democracies and to the modern welfare state, which depends on the willingness of citizens to pay taxes to aid fellow citizens whom they may never have set eyes upon.

Today’s nationalist revival is in reaction to the failure of global, not nation-based, initiatives that sailed over the heads of ordinary citizens. The reaction has been most potent on the political right, but there is certainly a basis for a liberal or social-democratic nationalism. If anything, the decline of liberal and social-democratic parties is a result at least in part of their inability to distinguish what is legitimate and justifiable in nationalism from what is small-minded, bigoted and contrary to the national interest it claims to uphold.