The party’s success has been built on targeted social transfers, genuflection to the country’s Catholic identity and avowed nationalism. But it also owes a lot to skillfully played campaigns of collective fear and demonization. For much of the party’s eight years in office, migrants, women and sexual minorities have been the chief targets. The government also regularly attacks the opposition, often in luridly conspiratorial terms. Its ministers and supporters suggest, for example, that the leader of the opposition and a former prime minister, Donald Tusk, plotted the plane crash that killed the Polish president in 2010. However outlandish, such conspiracy theories play into — and amplify — a pervasive fear that things are changing rapidly for the worse.

That fear is what undergirds the country’s response to the war. Poland’s modern history — annexed, subordinated and occupied — is one of a recurrent loss of independence. This tragic inheritance, never far away, explains the government’s energetic response to the war in Ukraine: The future must not repeat the past. And it’s not just Poland. A glance at the map is enough to see that the countries most muscular in their defense of Ukraine are those affected by the 1939 Nazi-Soviet pact, which exposed Finland, the Baltic States and Romania, along with Poland, to the depredations of conquering armies. Theirs is a solidarity based on the trauma of Russian imperialism.

The United States should take note. In February, on the anniversary of the invasion, President Biden spoke in front of the Royal Castle in Warsaw. After praising Poland as one of the United States’ “great allies,” Mr. Biden stressed the importance of defending freedom and democracy. It was a powerful speech. But freedom and democracy do not, in this part of the world, necessarily go hand in hand. Just look at the fact that the Law and Justice party, despite government scandals and sky-high inflation, sits comfortably at around 35 percent in the polls.

The party’s newly burnished international image as steadfast friend to Ukraine only helps to entrench such support. The government can plausibly present itself as the guarantor of security, both at home and abroad, underwritten by Western backing. Along with countries like India, Turkey and Rwanda, Poland may become part of the jigsaw of not-so-liberal friends of the West, helping to consolidate opposition to Russia and China. This process is happening for the convenience of the West — but not in adherence to its values.

It doesn’t have to be this way. The United States, for one, exerts considerable influence in Poland. If Mr. Biden, whose two visits to the country in the past year were major events, spoke out against the government’s domestic behavior, it would send a powerful message to party leaders. What’s more, Washington could make financial assistance — last year, the United States invested $288.6 million in Poland’s military — conditional on compliance with democratic standards and the rule of law. It might not work immediately: The European Union’s withholding of post-pandemic recovery funds to protest the government’s violation of judicial independence hasn’t reversed that slide. But it would show Poland’s illiberals that they can’t just do as they please.