The president of Catalonia, Carles Puigdemont, writes in the Guardian that “a de facto state of emergency” has ended Catalan home rule just weeks ahead of a planned referendum on independence. Madrid appears deaf to the argument that its heavy-handed attempts to stop the vote will only ultimately strengthen support for secession. A judge sent in the police to arrest a dozen local officials; the Guardia Civil seized millions of ballot papers; the central finance ministry took over the region’s finances to prevent public money from being used in the vote. All the Spanish prime minister, Mariano Rajoy, has achieved by being so oblivious to public sentiment in Catalonia is to harden opinion in the region and draw thousands onto the streets.

If nothing is done to work towards a compromise, a political train wreck threatens in the EU’s largest southern member state. This situation has been long in the making. A key tipping point came when Spain’s constitutional court in 2010 knocked down parts of a revised “statute of autonomy” – the result of a compromise reached four years earlier between Madrid’s then Socialist prime minister and the then centre-right Catalan nationalists. That was a document which boosted Catalonia’s already impressive levels of self-government. But Mr Rajoy’s conservative People’s party had lambasted the agreement as a dagger aimed at the heart of Spain’s 1978 constitution, and appealed to the constitutional court. Their victory there caused a reaction: the Catalan political leadership shifted towards separatism.

A “consultative” referendum was held in 2014, which Madrid denounced as illegal – as it plans to do for the 1 October vote – and kept the question of independence alive. Spain is already a federation in all but name. The 1978 constitution devolved large powers to regional entities – with only defence, diplomacy and taxes being the exclusive realm of the central government. Catalonia has thrived under this arrangement in many ways over the years. Simplistic slogans and radical stances cannot hide a crucial fact, which is that Catalans are highly divided on the question of independence. Recent polls show only 41% are in favour. But Catalonia does want the freedom to decide.

Mr Rajoy’s legalistic approach rests on clear court decisions, but he has shown a disturbing indifference to the demands of a large number of his citizens. He wants to speak for a majority of Spaniards, but has yet to prove he has the political skill to safely navigate this particular crisis. Catalonia’s leader seems set on proceeding with the planned independence referendum despite the arrests and seizures, but with ballots now confiscated, and uncertainty over voting lists, there is a risk its legitimacy will be even easier to dispute than the previous one (when turnout reached only 35%). Ignoring the constitutional court means breaking the law.

The clash between the demands of the law and those of political sentiment on the ground risks a horrible disaster both for Catalonia and Spain as a whole. Article 155 of Spain’s constitution allows Madrid to suspend the Catalan government’s authority to rule. Mr Rajoy has not yet exercised that option, and he would do better to avoid it. It’s true a large majority does want a referendum to be held but even if both sides are presently acting, and talking, as if this would lead to a vote for independence, this is by no means certain. Mr Rajoy should have the courage of his conviction that the status quo is better for both sides.

In Brussels, officials have made clear that a unilateral declaration of Catalan independence would mean an exit from the European Union – with no obvious path back in. Perhaps an EU mediation effort could make sense. But for any mediation to succeed, both Madrid and Barcelona have to step back from the brink. It is high time to start a dialogue. Spain, in all its diversity, achieved a remarkable democratic transition after Franco. Today, it would only win more admiration if a rational, political solution were to be found.