Across much of the world, fear-mongering and xenophobia are creeping into public and political discourse.

In liberal democracies with traditions of free speech, vociferous denunciations of these attitudes can act as a counterweight. But in authoritarian countries where alternative narratives are forbidden, official attempts to demonise foreigners and “others” can be especially dangerous. In the past week, the Chinese government has launched several viral online videos that blame “western hostile forces” for a host of ills and supposed conspiracies within China.

The videos are crude but exceptionally powerful in their simplicity and emotional appeal. One video promoted by the Supreme People’s Procuratorate and Communist Youth League, two of the most powerful state bodies, begins with heartbreaking scenes of orphans and victims of the wars in Iraq and Syria, and then jumps to an assertion that the west, led by the US, is trying to subject China to the same fate.

“Under the banner of ‘democracy, freedom and rule of law’ western forces are constantly trying to create societal contradictions in order to overthrow the [Chinese] government,” the subtitles read over pictures of democracy protesters in Hong Kong and President Barack Obama meeting the Dalai Lama.

According to the video, western plots and the “dark shadow of the Stars and Stripes” are also to blame for everything from attacks on Chinese peacekeepers in Africa, to farmers’ riots in China’s hinterland, to the Tibetan independence movement. The effect is heightened by ominous music and juxtaposition of chaos elsewhere with heroic images of Chinese soldiers and weaponry.

In some ways this is a mirror of the populist, jingoistic tilts happening elsewhere in the world. While not a direct reaction to the assertive Trumpism emanating from the US or the rise of rightwing nationalism in Europe, some of the same collective animus is taking hold in China, partly at the instigation of the ruling Communist party.

Many of those propagating this message are the shallowest of nationalists — the kind of party apparatchiks who are diversifying their (often ill-gotten) assets abroad as fast as they can and sending their children to study in Australia, the US, Canada or the UK.

Indeed, one of the main producers of the video on western plots is a 29-year-old PhD student from China now living in Canberra, Australia. Meanwhile, the party has called for the rejection of western values and concepts in favour of Marxism — an ideology named after a German living in London and refracted into China via Moscow.

Regardless of the hypocrisy and contradictions, this kind of propaganda is highly effective and gives licence to ordinary people to indulge their most primitive prejudices.

The privileges Chinese officials and many ordinary citizens used to extend to foreigners should never have existed

Since President Xi Jinping took power in late 2012, there has been a noticeable negative shift in Chinese attitudes towards foreigners living in the country.

In the past, most foreigners in China enjoyed a certain level of unstated protection and privilege. In business and in everyday life “foreign friends” were welcomed and often treated with kid gloves by the authorities. Some of them undoubtedly took advantage of this to flout the rules or behave badly without fear of retribution.

Today, that informal immunity seems to have vanished. In its place are hints of a backlash that many long-term foreign residents will tell you can be very ugly, ranging from casual discrimination and racial slurs, to physical altercations that take on a racist dimension.

This extends from individuals to the treatment of multinationals companies that increasingly complain about the absence of a level playing field in China.

The privileges Chinese officials and many ordinary citizens used to extend to foreigners should never have existed. But the calculated and repetitive demonising of “western hostile forces” risks whipping up the kind of xenophobia that will limit the government’s own room for manoeuvre in the future.

By convincing its people that many of China’s ills are the work of foreign spies and conspiracies, Beijing could eventually be forced to hit back against such perceived enemies in order to placate popular outrage. The less welcoming environment is also to blame for recent slipping foreign direct investment and an exodus of international talent.

China’s impressive economic rise began nearly four decades ago with a policy known as “reform and opening” and since then the country has been more open to the outside world than at almost any time in its very long history.

An end to that openness would be terrible for China and the world.

jamil.anderlini@ft.com