Garvan Walshe is a former National and International Security Policy Adviser to the Conservative Party. He runs Brexit Analytics.

It was 8.30 in the morning when the first pictures began to appear, on Spanish social media, of policemen in black helmets and body armour making their way towards buildings used as polling stations in Catalonia’s banned referendum. This was not going to end well.

Sure enough, the videos began to surface: old men being hurled away from a voting queue, a lady in her 50s with a bloodied face, people being thrown down stairs. Firemen facing off against the police in riot gear.

Until that Sunday morning, Madrid had managed the crisis well. The Catalan nationalist government, elected to office with a narrow parliamentary majority, but on only 48 per cent of the popular vote, had torn up parliamentary procedure to ram emergency referendum legislation through the regional Parlement.

The courts had ruled the referendum illegal (the Spanish constitution, like most, forbids attempts at secession). Judicial investigations for misappropriation of funds had been opened. The leaders of the independence movement faced fines and disqualification from office.

A whole set of ballot boxes and papers, intended to be used for the voting, was confiscated.

“Unionist” Catalans (around half the population) planned to stay away. A low turn out was bound to invalidate the poll and any declaration of independence that might follow a nationalist “victory.”

The provincial Catalan police, bearing the historically resonant name Mossos de Esquadra, were instructed to close polling stations that morning. The method they chose to do so was light touch – they sent pairs of officers to each station to inform the organisers that the referendum was illegal and if they kept them open they would be subject to prosecution.

Someone – we don’t know who, but it would be astounding if they had not taken this decision without highest political authorisation – decided this was not enough. An hour or so after polls opened, in those parts of Barcelona where the media were most likely to be present, they chose to send in the riot units of the National Police and Guardia Civil.

Worried that images of Catalans queuing to vote would grant the referendum legitimacy, Madrid instead contrived to generate footage of peaceful civilians under attack from uniformed goons of the state. By this means, they closed 91 polling stations. The Mossos, using their softer tactics, closed 221.

Short of sending tanks into the streets, it is hard to think of a measure more calculated to inflame nationalist feeling, deprive the Spanish government of the moral high ground, and hand the initiative to the nationalists.

Instead of discussions about the ease with which people could vote multiple times or the risible turnout, the story of the day became Spanish police brutality.

The tin-eared reaction of Mariano Rajoy, Spain’s Prime Minister, served to heighten, not dampen down, tensions.

Though he was right the criticise the Catalonian government for acting in contempt of the law, he foolishly limited himself to praising the role of the security forces and their “proportionality” in upholding it.

This would have been the time to beat a tactical retreat. Explain that, while the referendum was illegal and those responsible for holding the supreme court in contempt would be brought to answer before justice, there were clearly mistakes that had been made and measures would be taken to restore the confidence and legitimacy of national authority in all parts of Spain.

Instead, the King was wheeled out to make a televised address, inviting comparisons with the appeal for democracy that his father made on the occasion of the attempted military coup on 23rd February 1981. The relatively inexperienced King Felipe did not measure up to his father’s standard. His legally correct but politically shortsighted speech failed to reassure both sets of Catalans – those who feared being drummed out of Spain by nationalist extremists; as well as nationalists whose worst fears about the Spanish state were confirmed last Sunday.

I understand from sources close to Spain’s governing Partido Popular that their long-run strategy had been to provoke a confrontation with the nationalists. Though unwise (better, if you’re trying to keep the country together, to reduce tensions and expose your opponents as unreasonable), this could at least have been rational if accompanied by the tactics to win the conflict you provoke.

But when your opponents delight in weaving a “black legend” of Castillian oppression stretching right back to the War of Spanish Succession and through Franco’s regime (a partial interpretation of history, narrated at the Catalan taxpayer’s expense at, for instance, Barcelona’s El Born market museum), it is unforgivably stupid to act in the character they have created for you.

To accommodate the extra police sent to Catalonia, Madrid chartered a boat painted with loony tunes characters and moored it in full view of the city. An amusing coincidence at the time, it now looks to have foreshadowed a strategy worthy of Wile E Coyote’s self-defeating explosive experiments in pursuit of the roadrunner.