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.The bold supranational initiatives of globalization — a system of floating exchange rates in relation to the dollar; the unrestricted flow of capital; free trade (with few tariffs and government subsidies) monitored by the new World Trade Organization; the expansion of NATO and the European Union to ensure that former Communist states became liberal capitalist democracies — have unquestionably done some good. They helped expand trade and benefited immigrants who fled from less to more developed nations.But in the United States and Western Europe, none of these initiatives really delivered as promised. The global economy has suffered a succession of financial crises culminating in the Great Recession and continuing to this day in Turkey and Argentina. The free movement of companies has led to a global race to the bottom for wages, taxes and regulation and to growing inequality within nations. Instead of producing convergence between the richer export-driven economies of Northern Europe and the less developed countries of Southern Europe, the euro has widened the gap between them.They also failed to transform the global order in a way beneficial to Western democracies: NATO’s expansion eastward, betraying a pledge the George H.W. Bush administration made to Soviet leaders, contributed to rising conflict with the new Russian federation. And China’s entry into the W.T.O. didn’t lead to Beijing embracing free enterprise and liberal democracy. China used its command economy to run huge trade surpluses with the United States and Europe, helping to create a new class of angry “left-behinds” in factory towns in the American South and Midwest and in northeastern England.The rush of immigrants in the United States has brought about a clash of culture just as it had in past centuries. Employers have also used low-skilled immigrants to undercut unions and to turn mid-wage jobs in construction, meatpacking and janitorial services into low-wage labor. After Sept. 11, 2001, the resentment toward immigrants became fused with a rising fear in the United States and especially in Europe of Islamist terrorism. That created a huge political backlash against immigrants and refugees.Put that backlash together with the anger bred by lost manufacturing jobs and declining social services from reduced tax revenues, and you have the political base for Mr. Trump’s victory in 2016, Brexit and Italy’s League party.In the United States, Mr. Trump’s nationalist policies have not been without merit. Where his predecessors have feared alienating China, he has boldly challenged its transfer of technology, cybertheft and hidden trade subsidies and barriers. He has also spoken up for American manufacturing industries and their workers, and chided footloose companies like Nabisco, Ford and Carrier.But much of what Mr. Trump has done to make America great may eventually make it poorer. His corporate tax cut accelerates globalization’s race to the bottom. Much of the savings have already gone to corporate buybacks rather than new investment, and the resulting loss of tax revenues will threaten social spending for the people he claims to represent.His Hobbesian take-no-prisoners approach to trade and foreign policy — sowing conflict with allies as well as rivals and foes — will threaten the underpinnings of global peace and prosperity, which still depends on a grudging acceptance of American economic and military power. There are already foreshadowings of future financial disorder — in discussions by the European Union, Russia and China to defy American sanctions against Iran by creating a new funding authority that would evade the dollar and by Russia and China’s decision to use their own currencies rather than the dollar as the medium of exchange. Mr. Trump’s immigration initiatives, too, have merely reinforced cultural resentments and done little to stem the oversupply of unskilled and easy-to-exploit unauthorized immigrants.In all of these areas, Mr. Trump has harmed, not strengthened, our nation. Yet in the United States, the liberal opposition has generally failed to acknowledge what is valid in the today’s nationalist backlash. Many liberal pundits and political scientists continue to echo Hillary Clinton in characterizing Mr. Trump’s supporters in 2016 as deplorables. They denounce Mr. Trump’s tariffs without proposing any plausible means of counterbalancing the huge surpluses from China and Germany. They dismiss as a lost cause the attempt to revive the towns of the Midwest and South by reviving manufacturing. They rightly insist that the United States find a way to integrate and assimilate the country’s 12 million or more unauthorized immigrants, but they ignore the continuing flood of people without papers crossing the border or overstaying their visas and they dismiss attempts to change national priorities toward skilled immigrants. Here is the simple truth: As long as corporations are free to roam the globe in search of lower wages and taxes, and as long as the United States opens its borders to millions of unskilled immigrants, liberals will not be able to create bountiful, equitable societies, where people are free from basic anxieties about obtaining health care, education and housing. In Europe, social democrats face very similar challenges with immigration, refugees and euro-imposed austerity. To achieve their historic objectives, liberals and social democrats will have to respond constructively to, rather than dismiss, the nationalist reaction to globalization. John B. Judis is the author of, most recently, “The Nationalist Revival: Trade, Immigration, and the Revolt Against Globalization.” Follow The New York Times Opinion section on Facebook and Twitter (@NYTopinion).