The attacks were in different continents and on people of different faiths and of none, but in the North Carolina university town of Chapel Hill and the Danish capital, Copenhagen, it was freedom itself that was the intended target. On Tuesday, three young Muslim students were gunned down in their Chapel Hill flat, apparently by a neighbour, Craig Hicks, who claimed their faith was an affront to his atheistic principles. The attack on Saturday in the Danish capital was wider. To judge from the chilling audio of a prolonged volley of shots in which one man died, it seems to have been meant as a massacre of people at a debate on free speech, where the controversial Swedish cartoonist Lars Vilks and the French ambassador were present. From there, the gunman escaped and resurfaced to attack party-goers at a bat mitzvah, apparently with the simple objective of murdering Jews and terrorising the Jewish community. He was stopped only by the bravery of two police officers and a volunteer security guard, Dan Uzan, who was shot dead. The freedoms essential to democracy risk being slowly undermined by what the Jewish writer Natasha Lehrer has called a narrative of polarisation.

There can be no league table of victimhood in these acts of terrorism, but in the Scandinavian countries, which see themselves as uniquely fortunate in their social cohesion – “our fairytale country”, as one Danish mourner put it on Sunday – they have a shattering impact on self-belief. Five years ago the rightwing extremist Anders Breivik slaughtered more than 70 children at a Labour party camp in Norway. Now the Danes are experiencing the pain. Like France after the Charlie Hebdo attack last month, they are paying a high price for protecting the right to free speech. As in France, it is a right controversially exercised in Denmark with the publication of a series of cartoons in September 2005 depicting Muhammad. But all of Europe is engaged in an unprecedented struggle to balance the fundamental rights that are its priceless postwar inheritance with the most cherished beliefs of its new citizens. The right to free speech has to be weighed alongside the importance of respecting difference. In protecting one, there is always the risk of undermining the other. The same is true in the search for balance between freedom and security. On one hand, it seems that the Danish killer was already known to the security services. That suggest there is no prima facie case for greater powers of surveillance. But it is salutary that he was tracked down and shot dead by police because of the widespread availability of images from security cameras that other European countries, Germany for example, regard as an unacceptable invasion of privacy.

Freedom of speech is only one of the freedoms under attack. So is the freedom of worship, indeed the freedom to be different. After Amedy Coulibaly murdered four shoppers in a kosher supermarket in Paris last month, and the earlier deadly attack on the Brussels Jewish museum, it is clear that Jewish communities across Europe are under threat from a hatred that may claim its origin in opposition to Israel and Zionism, but whose form resembles all too closely the dark history of antisemitism. The Danish prime minister, Helle Thorning-Schmidt, made an important statement in defence of the valued place of Denmark’s small Jewish community in her country, but it is understandable that some complain that it has come too late. Though that does not justify the ill-judged call from the Israeli prime minister Binyamin Netanyahu for “massive immigration” to his country, it is clear that, for too long, too little attention has been paid to the sharp rise in attacks on Jewish communities.

In a different context, a similar insensitivity to the threat to a religious community is apparent in the US. The killing of the three Muslim students by a gunman whose Facebook page contained violent threats against all organised religion, including Islam, was initially described by local police as a dispute over a parking place. The FBI remains reluctant to confirm whether or not it is investigating a hate crime. Surely, the point is that every American Muslim believes that it was. And that we must all relearn an old lesson: that only eternal vigilance can protect all our freedoms.