Carles Puigdemont, Catalonia's president. (Angel Garcia/Bloomberg)

SPAIN IS facing its worst political crisis since its return to democracy 40 years ago, thanks to the inflexibility of two key leaders. Carles Puigdemont, the president of the region of Catalonia, insisted on going forward with a referendum on independence against the ruling of Spain’s constitutional court and the sentiment of most of his constituents; now he refuses to forswear a declaration of independence. In response, Mariano Rajoy, Spain’s conservative prime minister, has reached for a drastic remedy: a takeover of the province by federal authorities, which could provoke mass civil disobedience or even violence.

Spain’s Senate is due to vote Friday on Mr. Rajoy’s invocation of a never-used constitutional article that allows “all measures necessary” to force a region to obey the law. There’s little question that Mr. Puigdemont’s government, a coalition of nationalists and the far left that was elected with less than half the popular vote, flouted the constitution by going forward with the Oct. 1 referendum. But the measures the federal government is threatening, including the removal of the Catalan government and a takeover of its police force, appear likely to provoke a backlash even among the majority of the region’s 7.5 million citizens who have opposed independence. Federal authorities have already jailed two popular leaders of the independence movement without bail on charges of sedition.

Mr. Puigdemont and his followers badly overestimated their ability to mobilize support for their separatist cause. Only about 40 percent of voters turned out for the referendum; Mr. Puigdemont’s claim that the 90 percent pro-independence vote among that minority is a mandate rings hollow. European Union leaders bluntly rejected his appeals for mediation and sided with the Madrid government, as did the Trump administration. Since the vote, hundreds of companies have shifted their headquarters out of Barcelona, a sign of the economic price it is likely to pay for its leaders’ folly.

Yet Mr. Puigdemont persists, threatening to have the Catalan parliament vote on a formal declaration of independence. That would please his coalition partners, the radical left Popular Unity Candidacy, whose anti-capitalist, anti-E.U. platform may explain in part why Russia’s state propaganda apparatus, including mouthpiece Julian Assange, has strongly supported the separatists.

Moscow will cheer if the standoff between Mr. Rajoy and Mr. Puigdemont destabilizes Spanish democracy. Western governments, including the Trump administration, should be pushing harder for compromise. There are two promising avenues. The first is a constitutional reform that would allow regions such as Catalonia more autonomy; Mr. Rajoy agreed to a proposal by the opposition Socialist Workers’ Party to have a congressional committee study it. The other is a fresh regional election in Catalonia, which is the right way to challenge Mr. Puigdemont’s leadership.

The Catalan opposition wants an election, as does Madrid. But any vote must not exclude pro-independence parties, no matter their legal wrongs. Mr. Rajoy’s hard-line actions risk driving more voters into the separatist camp. He should refrain from more repression and push for a political solution.