THE IMAGES of Spanish riot police firing rubber bullets and swinging truncheons at would-be voters in Catalonia on Sunday handed the region's leaders the perfect story line: of a repressive central government squashing an attempted exercise in democracy. But the blossoming political crisis in Spain is considerably more complicated than that. The heavy-handed tactics unwisely employed by Spanish Prime Minister Mariano Rajoy came in response to a reckless and irresponsible drive by Catalan nationalists to create an independent republic in violation of the law and, most likely, the wishes of the majority of the region's residents.

Catalonia's nationalist forces, which include factions from the far left as well as the right, gained a majority in the regional parliament in 2015 despite winning less than half of the vote. They then pressed ahead with plans for a referendum on independence even after Spain's constitutional court ruled it illegal; the 1978 Spanish Constitution grants considerable autonomy to Catalonia and other regions but unambiguously declares the state "indivisible." Following Sunday's vote, Catalan President Carles Puigdemont claimed a mandate for independence on the grounds that about 90 percent of 2.2 million voters voted yes. But turnout was just 42 percent — opponents of the measure massively abstained — and pre-referendum polls showed a solid majority opposed a split with Spain.

The cold response by European Union leaders to Mr. Puigdemont's appeal for support ought to have tempered his ambitions. The European Commission backed Madrid in describing the vote as illegal and said an independent Catalonia would not be part of the union. President Trump also rejected the independence movement; the Catalan nationalists' only backers are separatist-ruled Scotland, the pariah government of Venezuela and Russia's intelligence and propaganda apparatus, which mobilized its media outlets and social media bots in support of the separatists. Moscow evidently perceives the Catalan movement as another vehicle for dividing and weakening the democratic West.

Mr. Puigdemont’s supporters were suggesting Monday that he could declare Catalonia’s independence later this week, though he has said he would seek approval from the regional parliament. Mr. Rajoy’s government is meanwhile threatening that it will criminally prosecute senior Catalan officials or use a constitutional provision to suspend the region’s autonomy. Either move would be a mistake that would only do further damage to Catalonia and Spanish democracy.

The right course is that which virtually every responsible authority outside Spain is calling for: negotiations between Barcelona and Madrid. Mr. Rajoy could offer the Catalan region more autonomy. Even better, the two sides could agree on a legal means for Catalonia to hold a fair, free and legitimate vote. Genuine democracy is the best way out of Spain’s crisis; unfortunately, neither side appears ready to embrace it.