The rise of Poland since 1989 has been a firework show. Noisy, high-spirited, in some ways dazzlingly successful, there were also bangs and flashes that alarmed all Europe. But the economy grew with wild-horse energy. Tight control of the banks kept Poland almost immune to the 2008 crash and, by good luck, Poland wasn’t yet in the eurozone when the sovereign debt crisis blew open.

Politics and the media were vigorous, occasionally filthy, but free. And yet now democracy seems to be in danger. Less than three months after the election of a rightwing government with an absolute majority, young and old protesters gather roaring in the streets. The EU commission, unexpectedly prompt, has opened an inquiry into whether Poland has broken the union’s “democracy rules”.

Lech Wałęsa, ex-president and leader of the 1980 Solidarity revolution, says that the new government is making Poland ridiculous. Tempting to agree. The minister of defence thinks the Protocols of the Elders of Zion (that ancient antisemitic forgery) are probably genuine. The minister in charge of security was actually serving a suspended sentence for abuse of power and slander when he was appointed. The foreign minister thinks that the 2010 Smolensk air crash, in which President Lech Kaczyński and all his retinue perished, was a murder planned by President Putin.

And yet, even if the actors are ridiculous, the Polish drama is not. It is dangerous. And the danger is both to Poland and to the safety of Europe. Law and Justice (PiS by acronym) has in a few short weeks packed the Constitutional Court, politicised the appointment of prosecutors, abolished court consent for state access to private internet accounts and brought public broadcasting under direct government control. Unwise: for Poles, tampering with the constitution insults the very talisman of Polish independence. A second danger, ironically, is that the government itself is so unconvincing. The real power is held by Jarosław Kaczyński, leader of PiS, who has deliberately refused any public office. President Andrzej Duda and Beata Szydło, the prime minister, take their orders from him and squirm for his approval. Kaczyński is behaving like Józef Piłsudski, the brilliant but irascible prewar leader who brought Poland back to independence in 1918. He also avoided taking any office, but enforced his will on parliaments from his country house.

Ominous, too, is the way that opinion is dividing. There are two confronting Polands of roughly equal strength. One, including the PiS supporters, finds its base in eastern Poland among small, pious farmers and working-class families who have lost jobs and income through the change from a state economy to an often ruthless neoliberalism. The other Poland, usually better educated and better off, is desperate to preserve what it sees as the historic achievement of 1989: the first reasonably stable and prosperous liberal democracy in Polish history.

True, this split between traditional nationalists and liberal reformers has been visible for years. Maps of election results have often shown the ghostly boundaries of the partitions: old-fashioned religious patriotism where Russia once ruled, more open minds and liberal views in the old Prussian and Austrian zones. But now that contrast has been weaponised. Socialist and fringe parties have almost vanished: Kaczyński’s regime faces a young, outraged and increasingly coherent “liberal” front determined to resist and reverse all that PiS has done. The question is whether this confrontation can be managed peacefully.

In western Europe, onlookers hear snatches of Law and Justice rhetoric and conclude that the party can be dismissed as “fascist”. It is not. It stands for an old-fashioned authoritarian nationalism, invoking traditional Catholic values (imprudently, some in the Catholic hierarchy lend PiS support). And, strangely for westerners, this frantically rightwing party is also the party of what remains of the welfare state, standing up for those millions for whom the transition to capitalism has brought only loss and bewilderment.

But this new government has also restored to Polish politics its most fatal flaw. This is the instinct that the winner must take all. That drives immediately towards political command of the judiciary and the media. It leaves no room, in the end, for the concept of an “independent” civil service or public institution (such as a broadcaster). As in the Communist times, “impartiality” is despised as a luxury western import. Worst of all, it invites politicians to identify their opponents as traitors to the nation. The brief PiS coalition government eight years ago spawned paranoid conspiracy theories against its critics, sometimes in racialist terms. (I remember going to a so-called “international conference on press freedom” in Warsaw: liberal and leftwing journalists were excluded, while the invited hacks made dotty speeches about patriotic duty and media subversion by foreign bribery.)

Historians can trace this paranoia back to distant centuries, when political opposition often really was financed by tsars and emperors determined to wipe Poland off the map. Today it’s daft. And yet the latest criticism from Brussels inspires a rightwing magazine cover showing European leaders wearing Nazi uniform: “Once again they want to subjugate Poland.” The PiS government is “anti-European”. But that doesn’t mean that its supporters want to leave Europe. Poles consider that their “Christian values” make them more European than anyone else on the continent. That is why, even though many Poles feel entitled to accuse the EU of encouraging atheism, individualism and immorality, an amazing 75% of them want to stay in the EU.

If there is danger to Europe here, it is strategic: that this Warsaw government could lose its head over eastern policy. Once Poland was imperial, seeking to dominate the regions of Ukraine, Belarus and Lithuania where there were Polish minorities. But after 1989, the first free government under Tadeusz Mazowiecki dropped all such claims and proclaimed that Poland’s mission would be to do all in its power to protect independence and democracy in those emerging nations. This brave act ran in the face of resurging nationalism. Super-patriots and older people expelled from homes in the east dreamed of seizing back the “lost cities” of Lwów and Wilno (Lviv and Vilnius) from the crumbling Soviet Union. But Mazowiecki’s renunciation stabilised the eastern frontiers of the European Union. In Ukraine’s 2006 Orange Revolution, it was President Kwaśniewski of Poland, more than anyone else, who averted a Russian intervention.

There is a big difference between intense vigilance towards Russia and hysteria. Nobody has more experience than the Poles of living – and sometimes dying – next to Russia. But it’s little comfort that Kaczyński’s ministers and followers are almost as rude to the Germans as they are to the Russians. Demonising Russia with myths and insults, as opposed to watching and standing firm, is taking the eye off the ball in a critical period.

If it stays on its course, this Law and Justice government will not only bring Poland to boiling point. It may undermine the security of all Europe.

Neal Ascherson’s books include The Polish August (1981) and The Struggles for Poland (1987)