To effect this transformation is one of the great political challenges of our age. It requires principled resistance to right-wing nationalism, but it can succeed only if those who are most open to diversity abandon their hostility to other forms of nationalism.

One common reaction to the dangerous excesses of nationalism has been to forgo the need for any form of collective identity, exhorting people to transcend tribal allegiances completely. But for better or probably worse, it’s easier to be moved by the suffering of people with whom we have some form of kinship. That is why nationalism remains one of the most powerful vehicles for expanding our circle of sympathy.

Another common reaction to the resurgence of nationalism has been to celebrate more narrow forms of collective identity, such as race or religion. At a time when many minority groups are under attack, it is, of course, crucial to defend them against discrimination. But it is also important to remember that such groups, too, are capable of oppressing their own members, for example by enforcing restrictive moral codes. That’s why the only way to allow individuals true freedom to lead their lives is to preserve some form of political identity independent of the interests of particular cultural groups.

Convinced that they would be unable to redirect nationalism toward their own ends, many of the most open-minded segments of society long ago gave up on the fight to determine its meaning. In countries like Germany and the United States, advocacy for the victims of prejudice has increasingly bled into a belief that the dark chapters of those countries’ history make any form of nationalism deeply suspect. Instead of exhorting their fellow citizens to live up to their nations’ highest ideals, many activists seem content with denouncing past and present injustices. This has allowed the bigots and racists to bend the meaning of the nation to their own sinister ends.

It’s time to fight back. Nationalism can, and should, be reclaimed for liberals.

A few political leaders have made a valiant start. Barack Obama has been an especially persuasive advocate of the idea that Americans should focus on what unites rather than what divides us and that the symbolism of the nation can inspire hope, even as we reckon with the injustices of American history. “What greater expression of faith in the American experiment than this,” Mr. Obama marveled as he stood on the spot in Selma, Ala. where civil rights protesters were beaten in 1965. “What greater form of patriotism is there than the belief that America is not yet finished, that we are strong enough to be self-critical, that each successive generation can look upon our imperfections and decide that it is in our power to remake this nation to more closely align with our highest ideals?”

Campaigning for France’s presidency last year, Emmanuel Macron expressed inclusive patriotism in an even more explicit form. “I see Armenians, Italians, Algerians, Moroccans, Tunisians,” he said at a rally in Marseille, a diverse city in southern France, “But what do I see? I see the people of Marseille! What do I see? I see the people of France!” This, he added in an explicit repudiation of the exclusive nationalism propagated by the far-right National Front party, “is what it means to be proud to be French!”

American — and to a lesser degree European — political culture is pregnant with the symbols of inclusive patriotism. But while we have plenty of history to build on, we must also recognize that we are fighting to establish a kind of society for which there is no clear precedent.