Protesters wave Polish and European Union flags during an anti-government demonstration in Warsaw on Saturday. (Alik Keplicz/Associated Press)

FOR TWO decades Poland has been a leader among the post-communist nations of Central Europe, with a rapidly growing economy and mounting influence as a member of NATO and the European Union. So the sudden eruption of a political crisis in Warsaw that senior political and legal figures say has endangered the country’s democracy has delivered a shock on both sides of the Atlantic.

The right-wing Law and Justice party, which won a majority in Parliament in an Oct. 25 election, has in a matter of weeks prompted the head of the European Parliament to talk about a “coup,” while tens of thousands of Poles have joined demonstrations by a newly organized Committee for the Defense of Democracy. The alarms were triggered partly by controversial appointments, including of a chief of security services previously convicted of abuse of power, and by suggestions that the new authorities will seek to purge the media or prosecute former prime minister Donald Tusk, now president of the European Council, the European Union’s highest body.

The government’s most disturbing actions, however, have been its attempts to gain control over the Constitutional Tribunal, which rules on the legitimacy of laws Parliament passes. Within days of taking office, Law and Justice sought to push through the appointment of five new justices while invalidating appointments the previous Parliament made. When the tribunal ruled this move unconstitutional, the government refused to recognize the decision. Now it is rushing new legislation through Parliament that would effectively paralyze the court by requiring that its decisions be made with a two-thirds majority.

The government’s defenders say critics are overreacting to its first moves and that the previous administration touched off the fight over the Constitutional Tribunal by improperly trying to install its own nominees at the end of its term. However, Law and Justice and its leader, Jaroslaw Kaczynski, crossed a line in not accepting the high court’s ruling, which validated three of the five previous court appointments. By making it difficult for the court to reach decisions, the new law could remove the most important check on the new government.

Poland remains a robust democracy, as the mass demonstrations and heated debate inspired by the court crisis demonstrate. But many Poles fear that Mr. Kaczynski, who installed follower Beata Szydlo as prime minister, intends to follow the course of Hungarian Prime Minister Viktor Orban, an ally who has severely compromised that country’s institutions while proclaiming his contempt for liberal democracy. The two leaders share harsh opposition to the E.U. policy of openness to Muslim refugees; Mr. Kaczynski once claimed they carry “various parasites and protozoa” that “could be dangerous here.”

Notably, Mr. Kaczynski and his party are hostile to Russia and distrustful of Germany, but they are broadly pro-American. That may give the Obama administration an opportunity to influence the government’s course. It should tell Warsaw’s leaders that weakening judicial checks, purging critics from state-owned media and pursuing the prosecution of political opponents will quickly sour relations with Washington — and undermine the Polish success story.