There are two cheering things about the results of the Swedish general election. The voters did not deliver the huge boost many had feared to the xenophobic Sweden Democrats (SD) and they continued the brutal punishment of the Moderates, the mainstream rightwing party once close to David Cameron’s Conservatives. In 2010, the Moderates gained 30% of the vote; now their share is down by more than a third, to 19%. The Moderates are being punished in part for their role in policies that gave the far right a chance at the big time. In government from 2006 to 2014, they believed in a small state and large-scale immigration. After the refugee crisis in 2015 when Sweden welcomed 160,000 refugees in a single year – which would correspond to a million in a country Britain’s size – the Moderates, along with all the other parties, lost their belief in immigration. To that extent SD had triumphed in the battle of ideas long before this election. Yet after this election it is still only the third-largest party in the country, and shunned – at least officially – by all the others, even though it holds the balance of power in parliament.

With all that said, the result is very bad news for the mainstream parties and not just the Moderates. The Social Democrats, who were for most of the 20th century the hegemonic force in Swedish politics and ruled the country for 44 years continuously, slumped to their lowest vote – 28% – since the advent of universal suffrage. The Social Democrats remain the largest single party in the country but are a long way from the dominance they once took for granted. They seem stale and out of ideas; what had once been a genuine mass movement is now little more than a political party.

There is an argument that the SD will have to be brought into open politics sooner or later; that a party that – wrongly – believes that foreigners can never be integrated into Sweden must itself be integrated there. At the moment it functions like the dark matter of the Swedish political system. Nothing the other parties do can be understood without its influence, but it is never itself clearly visible. Against this there are two decisive points. The first is that its radical rightwing policies are in fact clearly visible. Jimmie Åkesson, the party leader, campaigned all over the country and made his case on TV too. When he had done so his party was rejected by an overwhelming majority. The second is that the nativist passions to which he appeals are unusually dangerous and difficult for politicians to contain once unleashed.

The Sweden Democrats have long traded in brash populism: cultivating an image of outsiders and attacking both political elites and immigrants. Swedish voters, however, are not only concerned with the question of immigration, whatever some foreign newspaper coverage might suggest. The health service was consistently judged to be the most important issue; in some polls immigration came lower than education and equality. Violent crime is very localised, to particular areas and even streets. The welcome that the country extended to refugees turns out to have been rash as well as generous, and ultimately unpopular when welfare cuts were biting. But it has not destroyed the country or trashed its democracy, and with goodwill on both sides the refugees will in the end strengthen Sweden, to the benefit of everyone who lives there. For this to happen, though, the politicians must recapture the lost magic of social democracy, when it married patriotism with internationalism. That would be a model that the rest of Europe, and the UK, really needs to learn from in these troubling times.