"If you come to Denmark, you have to work," says the election poster in Copenhagen, Borgen country, which goes to the polls today.

And that is from the centre left Social Democrat party. The Danish Liberals are calling for an "immediate halt" to asylum seekers.

It's not the kind of sentiment you expect from this Nordic nation famed for its liberalism and advanced social policies. The establishment parties here, as in Britain, are on the defensive against a populist right wing party, the Danish Peoples Party, which is expected to become the third largest in today's general election, and may enter government after it.

It's the same story across the Nordic countries. Last month the far right True Finns (now just called the Finns Party) came second in Finland's general election and are now part of a centre right coalition. In Norway, Siv Jensen's Progress Party has been in government since 2013.

And in Sweden, the anti-immigration Sweden Democrats have the balance of power, brought down the government last year and have been holding the whip hand in the recent budget negotiations.

So, what's going on? How have these countries, with their equalitarian policies, high taxes and enlightened ideas apparently become susceptible to the appeal of ethnic nationalists parties who oppose multiculturalism and want to cut immigration?

Finland has what many regard as the best education system in the world, yet one of the governing parties is now calling on schools to promote Finnish identity in the classroom and start teaching "heathy national pride".

Well, the lesson here for everyone involved in the debate about Scotland is that, whatever advantages it might have in other areas, just being a small country doesn't immunise a society from the politics of the Right, any more than being a large country does.

Those who regard Denmark - as I do - as in many respects a model of a modern social democratic country, shouldn't expect that its people are in some way genetically incapable of prejudice or the politics of fear. And there is a lot of fear in Denmark.

In February an Islamic extremist murdered a documentary film-maker, Finn Norgaard, and injured several policeman in a machine gun raid on a Copenhagen cafe. The cafe had been due to host a talk by the Swedish cartoonist Lars Vilks, who has himself had to be protected by armed guards since he drew a cartoon showing a dog with the head of the Prophet Muhammed in 2007.

Later that day, a synagogue in Krystalgade was attacked by the same gunman who killed a security guard and two more policemen. The echoes of the Charlie Hebdo massacre in Paris were clear, though curiously the international reaction to the Danish murders was muted. You don't see people wearing Je Suis Krystalgade badges.

This equivocation by liberals, if such it was, has had the unfortunate consequence of allowing the Danish Peoples' Party to present itself as a leading advocate of freedom of speech. One of its posters reads: "Freedom of speech is Danish. Censorship is not. We stand our ground in Danish values"

The confrontation with Islamic extremism in Denmark goes back to 2005 when the Danish courts ruled the depiction of the Prophet in 12 cartoons in the paper, Jyllands-Posten, was not an offence against the Muslim people. There has been a real clash here ever since between a society defined by tolerance and a militant extremism which believes that tolerance is itself evil.

In Denmark this has led to a reaction against multiculturalism, even though barely 5 per cent of Danes are actually Muslim,and most of them - like the Kyrystalgade killer - were born in Denmark. But this is what terrorism is intended to do: sow division, encourage victimisation of minority ethnic groups.

Nordic countries are small cohesive societies, as the fictional mafia gangster in Lilyhammer discovered in Norway. There is an expectation of mutual self-help and integration which some find conformist and even culturally threatening.

In Denmark, people expect you to ride your bike, pay your taxes, clear your snow and behave the way Danes behave. This small northern country has a strong sense of national identity, keeps the EU at arms length and has retained its own national currency.

This is fertile ground for populist parties claiming Danish culture is being threatened by a failure of the Muslim community to integrate.

It is one of the reasons to be cheerful about Scotland's constitutional debate that ethnic nationalism and racialism have been almost entirely absent.

No-one here sees much point in making offensive cartoons representing religious leaders. Well, not Muslim ones anyway. Scottish voters doesn't seem to feel threatened by immigration, perhaps because we are nation of migrants ourselves.

Of course, Islamic extremists tried to blow up Glasgow Airport in 2007, so we are not exactly immune from terrorism here. That didn't create a wave of anti-muslim or anti-foreigner feeling, any more than did the Lockerbie bombing, which was the worst terrorist atrocity in UK history.

But we know from opinion polls that there are a lot of Scots who would like to see immigration curbed even though this hasn't been a decisive issue in Scottish elections. There are corners of Scottish society where it is still acceptable to be prejudiced against people of a different colour or religion.

However, to turn latent unease into full-scale grievance you need to have parties willing to exploit fear and prejudice for political ends. In Scotland, for historical reason, the SNP is, unlike nationalist parties in the North of Europe, a civic nationalist pro-immigrant party.

Any trace of ethnic nationalism, and anti-English sentiment, was expunged from the party in the 1970s. Nicola Sturgeon was the only party leader in Britain who, during the General Election debates, consistently and energetically argued that immigrants benefit society.

South of the border it is now almost impossible to make the positive case for "migrants" as they are called. Ukip has driven Labour so far to the right that every candidate for the leadership, except outsider Jeremy Corbyn, insists Labour "got it wrong" on immigration and that there needs to be a clamp down.

As for the Conservatives, the Nordic far right see David Cameron as something of an anti-immigration pin-up. The Danish People's Party enthusiastically support his refusal to accept EU quotas for Mediterranean boat people. The Finns Party love his anti EU rhetoric, though even they haven't dared call for EU migrants to be denied benefits for four years.

So, let us at least be grateful that there has been to upsurge - as yet - of racial, ethnic or anti-asylum seeking parties in Scotland. It is something that requires eternal vigilance and confident leadership to prevent a country from flirting with the dark side.

The SNP should not have to apologise for being patriotic, but it should always remember that intense love of country - as the pro-independence writer, Tom Nairn argued - can easily turn into hatred of foreigners. It is the job of democratic politicians not to succumb to the temptations of ethnic populism, but to take the lead in rejecting it.