Awful though the deadly incident was in the German city of Münster on Saturday, there was an almost audible sigh of official relief across Europe when the authorities there discounted a terrorist motive. These are nervy times in the European Union. The EU was conceived as a bastion of democracy and inclusivity. Yet it is easily rattled, not just by a man driving a van at a cafe, as in Münster, but also by the very act of democratic consultation of the people itself. It has become routine in Brussels for popular ballots to be seen as a problems to be navigated.

Last month it was Italy, where populist and xenophobic parties humbled more established pro-EU forces. On Sunday it was Hungary’s turn to trigger the alarm. At the time of writing, it was unclear whether Viktor Orbán’s Fidesz party had won a third successive term. But few doubt Mr Orbán’s capacity to cling to power or his contempt for tolerance and pluralism.

The Italian and Hungarian experiences are different, reflecting diverse histories and cultures. The common thread is fear of immigration. Many Italians and Hungarians perceive their countries to be frontline states of the EU. Italy absorbs refugees and migrants by land from the east and by sea from the south, across the Mediterranean. Hungary has erected a 155km barrier to limit crossings from the Balkans.

Anti-immigration policies are hardly new. But the politics of border control is acquiring an ever more ideological character as a culture war against alien infiltration. There is a growing tendency across the EU to depict immigration as a threat to the majority-Christian character of the continent. That, in essence, is an attack on non-white migrants from predominantly Muslim countries. The vicious and historically illiterate inference is that Islam is inherently incompatible with “European” values.

Heinz-Christian Strache, the leader of Austria’s far-right Freedom party and, since last year, part of the country’s ruling coalition, is a leading practitioner of this rhetoric. He warns of “Islamisation” as if it is a force poised to annihilate Austrian culture. Mr Orbán is even more blunt. He has described refugees from Syria as “Muslim invaders”. This language taps into anxieties, modern and ancient. It plays on economic insecurity and cultural disorientation after decades of heady globalisation.

But it also excavates deeper prejudices rooted in an ethnocentric idea of white Europe besieged by infidel hordes. This narrative is encouraged by far-right Islamophobic ideologues in the US, who have cultivated transatlantic partnerships. The danger hardly needs spelling out. Those who extol the Christian character of the continent fail to note that the relative religious homogeneity they romanticise has historically been achieved by genocide.

The EU was founded, in part, to eliminate the prospect of continental nationalism ever again achieving that murderous frenzy. But it is not easy for EU institutions to reassert that moral purpose when doing so looks like a repudiation of the democratic verdicts in member states. The nationalists’ idea of Europe is dangerous, and liberal politicians have been too complacent in thinking the Brussels-based institutional idea is a compelling alternative. The EU, as an idea and a set of rules, is indispensable as a bulwark against nationalism but not sufficient. Racist politics has taken hold at the grassroots level and that is where it must be defeated. The fight against fear will be won at the national level. Those who wish for a more tolerant and open Europe must make their case from first principles, passionately and without delay.