It’s ugly and on the rise; and it’s hard to see how it can end well. The global rise of conservative nationalism with the aim of creating “national communities” – directed by an unchallengeable leader to defend special national values, controlling borders against the virus of immigrants and “foreign” influence – is the menace of our times.

It is the recipe for domestic repression, crony capitalism, massive corruption, implosion of the rule of law, the rise of racism and international conflict. The values that underpinned the postwar liberal order that conferred peace, tolerance and prosperity are being torched before our eyes. It is time to take a stand.

Russia and China are the international standard-bearers of this malign credo, flanked by Turkey and India, and openly admired by the conservative nationalists in power in Poland and Hungary – and by Donald Trump, Nigel Farage and a leavening of extreme Tory Brexiters. All are spawn of the same devil – immigration and a working population that feels jobs and living standards under threat. All over Europe there are conservative nationalist parties beating the same drum – from Germany’s Alternative für Deutschland (AfD) to Denmark’s People’s party. Europe is reacquainting itself with its darkest demons.

Within the EU Hungary’s Fidesz party has been taking the lead, reshaping its constitution to create what its leader, Viktor Orbán, openly boasts is an “illiberal democracy”. The aim is a one-party state committed to root out anti-Christian values, with no effective checks and balances, controlling the media and a network of oligarchs who owe their fortunes to government contracts. It stinks to high heaven, but Orbán has two great cards – being in the frontline of Muslim immigration and a fragile economy. He wins elections, holding the supermajority in the Budapest parliament that allows him to do what he has done.

Since 2015, Poland’s Law and Justice party has been taking its lead from Hungary even though it has no parallel supermajority. There has been the same weakening of the constitutional court, the same gerrymandering and the same party takeover of state broadcasting. The aim is also the same: to build a nationalist community resisting multiculturalism and immigration, asserting Christian values and boosting the economy through contracts to favoured insiders.

Just before Christmas the EU said enough. It has given the Polish government three months to change policies or face fines, loss of voting rights in the EU and a cut-off of funds in the EU budgetary cycle staring in 2021. It is the most aggressive act against a member state in the EU’s history.

Last week the Polish prime minister, Mateusz Morawiecki, flew to Budapest to garner support from Orbán. Their countries, they declared, would together resist the forces of metropolitan liberalism in Brussels, Berlin and Paris. Because the EU can only proceed against a member state with unanimity, Hungary would veto any move against Poland. Neither country would accept its quota of immigrants, both vigorously defended their retreat from a liberal constitution. This was a fight for “the people’s will” and an idea of a national community.

Protests against a new law in Poland changing the makeup of the supreme court. Photograph: Rafał Guz/EPA

Orbán’s ideology was set out in an incendiary 2014 speech in Băile Tușnad – ceded to Romania after the 1920 Treaty of Trianon, which Orbán wants to reverse, extending voting rights to ethnic Hungarians in Romania. Hitler had the same passion for ethnic Germans living beyond Germany’s borders in the 1930s.

For Orbán the financial crisis of 2008 marked the decline of the west and its liberal values; in the future it would be systems that were “not western, not liberal, not liberal democracies, and perhaps not even democracies” that would create successful and competitive societies. Liberalism stood for “corruption, sex and violence”. He would cleanse Hungary and set it on an anti-liberal path – including the building of a razor-wire fence to keep out illicit Muslim immigrants.

Foreign political activists – “implacable human rights warriors”, he would later clarify – were the main obstacle to his programme. A particular target is Central European University, funded by George Soros, who happens to be Jewish, and run by foreign liberals. He wants it shut.

Yet two days ago Orbán was welcomed to speak to Bavaria’s Christian Social Union, Chancellor Merkel’s coalition partner. Its leader, Horst Seehofer, explained the invitation by saying he did not want to judge other nations – even while Orbán vigorously argued that this year would be when the “will of the people” in Europe is restored and their views on immigrants respected. Seehofer’s positioning is clear; a halo effect association with Orbán can only help him, given the increasing anti-immigrant sentiment in Germany, especially in the east, where the AfD is the second strongest party.

How great it would be if Britain were in the thick of this fight – but we too are in the grip of the populist right

After 1989 the EU made a bet. If it could create strong democratic institutions in eastern Europe, democratic values would follow – hence the 2004 accession of Poland and Hungary. Without mass Muslim immigration and the financial crisis, this bet might have held, even if it took generations for deeply held prejudices to fade. But that’s not where we are.

The EU is right to be tough with Poland but it’s a battle it must win. So, if Hungary and Poland want to build illiberal democracies, they must do it outside the EU’s structures and without EU funds. European capitalism may have been wounded by the financial crisis , but both it and the euro pulled through. Orbán is wrong to celebrate the Chinese and Russian economies – and he should be roundly taken on. His speeches are cover for feathering his cronies’ nests and indulging a supremacist ethnocentrism that borders on racism. It will only damage Hungary.

But the EU also needs to allay its populations’ fears about freedom of movement. Every member state should have the right to implement an emergency lock on immigration. The presumption should be openness, but not without limit. The attempt to deliver this is gifting the populist nationalist right everywhere a political free-run – and creating forces that may threaten the EU itself.

How great it would be if Britain were in the thick of this fight – but we too are in the grip of an anti-Enlightenment populist right. Theresa May has to court the Polish government to support the cake-and-eat-it trade deal she is fatuously pursuing. We cannot join with France and Germany standing for the best of European values because we need Poland’s support. Brexit is revealed to have the same dark roots that succour Orbán. Labour – internationalist, pro-European and profoundly anti-racist – should find the courage to speak out, and insist that in times like these to leave the EU is folly. The time for temporising is over.