If you are English and in your 50s or early 60s, two things are likely to be true of you. One is that in 2016 you voted to leave the European Union: 60 per cent of both men and women in the UK aged between 50 and 64 did so.

The other is that you were, in the immediate period after the UK joined the Common Market, a punk. Or if not an actual punk, then a vicarious one, living off the thrills of the most powerful and original English cultural movement of modern times.

These two truths are closely related. At the level of high politics, Brexit may be defined by upper-class twittery. It seems more PG Wodehouse than Johnny Rotten. But at the level of popular culture, it is pure punk. John Lydon (formerly Rotten), having initially opposed Brexit, later identified himself with it: “Well, here it goes, the working class have spoke and I’m one of them and I’m with them.”

They are all bad boys. It is not accidental that the far-right Faragist side of the Brexit movement chose to paint itself as a political wing of the Sex Pistols

In a sense, this is the wrong way round – they are with him, or at least with the Johnny Rotten of the mid-1970s. Had it not had the genius of Take Back Control, a perfect slogan for the Leave campaign would have been Never Mind the Bollocks, Here’s Brexit! For it is in punk that we find not just the nihilistic energy that helped to drive the Brexit impulse but, more to the point, the popularisation of masochism. What heroic failure and fantasies of Nazi invasion did for the middle and upper classes, punk did for the young and the working class.

Many Brexit voters were formed by its most breathtaking, counterintuitive stylistic gesture – the idea of masochism as revolt, of bondage as freedom. Punk took bondage gear out of the bedroom and on to the street; Brexit took coterie self-pity out of the media-political boudoir and into real politics.

Objectively, the great mystery of Brexit is the bond it created between working- class revolt on the one side and upper- class self-indulgence on the other. There would seem to be an unbridgeable gulf of style and manner – let alone of actual economic interests – between the stockbroker superciliousness of Nigel Farage or the self-parodic snootiness of Jacob Rees-Mogg on the one side and the raw two-fingered defiance of working-class patriotism on the other. Brexit depended on an ostensibly improbable alliance between Sunderland and Gloucestershire, between hard old steel towns and rolling Cotswold hills, between people with tattooed arms and golf club buffers.

One great binding agent was Anarchy in the UK, the sheer joy of being able to f**k everything up. Boris Johnson, who used The Clash’s London Calling as the theme song for his successful campaign to be mayor of London, also chose the same band’s version of Pressure Drop on Desert Island Discs in October 2005.

The supercilious Nigel Farage and the snooty Jacob Rees-Mogg represent just one aspect of the Leave side. Photograph: Dan Kitwood/Getty

On that programme, in a rare moment of self-reflection, Johnson spoke of the pleasure of making trouble that motivated his mendacity: “So everything I wrote from Brussels, I found was sort of chucking these rocks over the garden wall and I listened to this amazing crash from the greenhouse next door over in England as everything I wrote from Brussels was having this amazing, explosive effect on the Tory party, and it really gave me this, I suppose, rather weird sense of power.”

Essentially, this differs not at all – either as a psychological satisfaction or as a career move – from the way Johnny Rotten made himself famous: “Johnny Rotten, a member of the group,” the Guardian reported in 1976 after The Sex Pistols had exploded into wider British consciousness in an outrageously offensive TV interview, “said in a BBC interview that he had launched himself to stardom by walking up and down the King’s Road in Chelsea, spitting at people. ‘I did it because they were stupid’.”

Throwing rocks over the garden wall to hear the crash from the neighbour’s greenhouse windows is the upper-middle-class Home Counties version of spitting at people on the King’s Road because they are stupid. And each has the same performative quality of edgy clowning in which everything is at once very funny and highly sinister.

The somewhat despairing question that Bill Grundy asked in his notorious Sex Pistols TV interview – “Are you serious or are you just… trying to make me laugh?” – hangs over Johnson’s entire political and journalistic career. Tory anarchism always had a taste for the outrageous: before the Sex Pistols said “f**k” on television, the last person to do so was Sir Peregrine Worsthorne, then deputy editor of the Sunday Telegraph and an obvious journalistic model for Johnson.

They are all bad boys. It is not accidental that the far-right Faragist side of the Brexit movement chose to paint itself as a political wing of the Sex Pistols. Its supplier of dark money, Arron Banks, called his hastily cobbled-together book The Bad Boys of Brexit: Tales of Mischief, Mayhem & Guerrilla Warfare in the EU Referendum Campaign. “Let’s shake this up,” Banks records himself saying to Farage in July, 2015, as they are planning what would become an openly racist campaign. “The more outrageous we are, the more attention we’ll get; the more attention we get, the more outrageous we’ll be.”

BREXIT: The Facts Read them here

Mischief, mayhem, bad boys, brutal laddish mockery, the knowledge that the more outrageous they were the more attention they would get – all of this was pioneered by the Sex Pistols’ Svengali, Malcolm McLaren.

It would be a good quiz question to ask whether this passage is by McLaren or Banks: “I had created a feeling that was both euphoric and hysterical. On that tour bus, you couldn’t help but be aware of an enormous range of possibilities – that whatever was happening couldn’t be predicted, that it was a movement towards a place unknown. We had the means now to start a revolution of everyday life.” It is actually McLaren on the Pistols’ first tour, but it could describe the careening course of the Brexit campaign.

The Sex Pistols: Upper-class twittery may define Brexit but in popular culture, it is pure punk. Photograph: Michael Ochs Archives/Getty

Aside from these affinities between Tory anarchism and punk nihilism, there are two deeper ways in which being a punk in the 1970s might have prepared you to be a Leave voter in 2016. One is that punk was actually a brilliant, unexpected and thrilling reinvention from the bottom up of the English cult of heroic failure. McLaren’s enterprise was consciously self-destructive: “My intention was to fail in business, but to fail as brilliantly as possible. And only if I failed in a truly fabulous fashion would I ever have the chance of succeeding.”

More importantly, for the young people who actually adopted it, punk was a way of reclaiming dignity by defiantly celebrating their own failure to get on in the approved manner. Its style was the playing up of wretchedness, the creation of fashion from the detritus of consumerism – wearing bin liners and ripped T-shirts, turning the safety pin, shameful emblem of poverty, into a form of decoration. It was the ultimate triumph of failure – and of treating triumph and failure as twin imposters. It is not far as it seems from the stiff upper lip to the curled lip, from the heroic not caring of Capt Scott to the great snarl of Rotten’s “And we don’t care” at the end of Pretty Vacant.

But punk also created the most powerful paradox in the deep neurosis of Brexit: the strange psychic mash-up of revolt and pain, of bondage and freedom, of liberation and self-harm. McLaren and Vivienne Westwood’s clothes shop, Sex, sold “fetish wear – rubber and leather gear – that would at once appeal to a specialised market and be adopted by teenagers”. The idea, as Westwood explained, “was to take these taboo garments out of the bedroom and into the streets: now that would be really revolutionary!”

It is striking that this idea of sadomasochism as “really revolutionary” dovetailed with the more mainstream masochistic fantasy in the English reactionary mindset that England had really lost the second World War because Germany had subsequently taken it over by stealth through the EU. Punk had its own version of the Nazi invasion of England.

One of Johnny Rotten’s signature Westwood-designed shirts, worn with bondage-style leather gear, has the slogan “Destroy”, an altered image of a penny postage stamp in which Queen Elizabeth’s head is being cut off, and a huge swastika. In Dennis Morris’s iconic photograph, Rotten, while wearing this outfit, is posed like Christ on the Cross, the ultimate image of glorious suffering.

The English generation that was shaped by punk thus absorbed more than a renewed and radically re-energised idea of heroic failure. It was familiarised with what would otherwise be an outlandish contradiction – the fusion of freedom with self-inflicted pain. Wild revolt is one side of the coin but the other is pleasurable confinement, restriction, bondage. There is in this complex structure of feeling both a breaking free and a submission to being tied up. A single sentence of McLaren’s says it all: “These trousers, our bondage trousers, were a declaration of war against repression.” To translate that into bad boy Brexitese: any transgression is revolutionary even if it celebrates self-harm.

Boris Johnson’s inability to take power meant the English revolution became more like a medieval carnival in which the crowd proclaims the village idiot king

Why do people cut themselves? Obviously, because they are unhappy, frustrated, angry. They feel that no one cares about them, no one listens to them. But it still seems hard to understand the attractions of inflicting pain on yourself. Three things seem to make cutting addictive. One is that it gives the pain you feel a name and a location. It becomes tangible and visible – it has an immediate focus that is somehow more tolerable than the larger, deeper distress. The second is that it provides the illusion of control. You choose to do it – you are taking an action and producing a result. It is a kind of power, even if the only one you can exercise that power over is yourself and even if the only thing you can do to yourself is damage. And the third is that it can seem in an unhappy mind like an act of love.

You can hurt yourself for someone or something. “So,” sings the great balladeer of English self-pity Morrissey, “scratch my name on your arm with a fountain pen. This means you really love me.” For some, marking Leave on the ballot paper in June 2016 was a way of scratching the name of England on their arms to prove their love.

The distress is real. And Brexit gives the pain a name and a location – immigrants, and Brussels bureaucrats. It counters their sense of powerlessness with a moment of real power – Brexit is, after all, a very big thing to do.

But it’s still self-harm. For the cynical leaders of the Brexit campaign, the freedom they desire is the freedom to dismantle the environmental, social and labour protections that they call “red tape”. They want to sever the last restraints on the very market forces that have caused the pain. They offer a jagged razor of incoherent English nationalism to distressed and excluded communities and say “Go on, cut yourself, it feels good.”

It does feel good. It is exhilarating and empowering. It makes English hearts beat faster and the blood flow more quickly – even if it’s their own blood that’s flowing. But the crucial twist is that this self-harm is politically bearable only if someone else is being harmed more. The masochism doesn’t work without a compensatory element of sadism.

Brexit is often explained as populism, but it is driven more by what Timothy Snyder in The Road to Unfreedom calls “sadopopulism” in which people are willing to inflict pain on themselves so long as they can believe that, in the same moment, they are making their enemies hurt more: “Such a voter is changing the currency of politics from achievement to pain, helping a leader of choice create sadopopulism. Such a voter can believe that he or she has chosen who administers their pain, and can fantasise that this leader will hurt enemies still more. [This] converts pain to meaning, and then meaning back into more pain.”

Brexit did have a leader in Boris Johnson, but he was too incompetent to effect the transfer of power needed. Photograph: Charles McQuillan/Getty

This definition illuminates much of what is going on in Brexit, but it also highlights the project’s short-term problems and long-term contradictions. The most obvious short-term problem is the “Leader of choice”. Snyder is thinking of Vladimir Putin, Donald Trump and their various imitators in Europe and elsewhere. Brexit did have a leader of choice – Boris Johnson – but he was too incompetent to actually effect the transfer of power that this revolutionary moment needed.

Johnson’s inability to take power (or to use it when he got some of it as foreign secretary) meant that the English revolution immediately became more like a medieval carnival in which the crowd sweeps up the village idiot and proclaims him king for the week. Johnson was in fact King Brexit for slightly less than a week, from the morning of the referendum result on June 24th, 2016 to his ignominious withdrawal from the race to succeed David Cameron as prime minister on June 30th.

If Johnson was the only great leader who could save the Brexit project, it was inevitably doomed. The manner of his failure may have been spectacularly inept, but in fact Johnson was bound to fail. He embodied a fatal flaw in the Brexit project: the self-pitying grievances that it was designed to address could not in fact be addressed. Why? Because they did not exist. A revolution must cloak itself in an idea of justice: the wrongs done by our oppressors will now be righted. Political prisoners will be freed, exiles returned, land redistributed, collaborators punished, heroes rewarded. But there were no EU dungeons to be thrown open. There were only trivial fictions.

The revolutionary regime that Johnson was supposed to lead could not restore the right to give donkey rides on beaches, or bring curved bananas back to the shops, or stop dictating the precise size and shape of a Christmas tree, or liberate British trawlermen from the ignominy of having to wear hairnets. All of these had been reported in British tabloids as oppressive realities but they were just vivid stories. Prawn-cocktail flavour crisps – whose alleged banning by the EU was Johnson’s first great Brussels-bashing fiction – could not be restored to the millions of children craving them for the simple reason that they had never ceased to be available.

The camp, ironic discourse that underpinned Brexit was an in-joke that could not live outside the very thing it sought to subvert, the EU

The point about the whole Borisovian Brussels-bashing project was that it could survive anything except success. Its great strengths were its apparent tangibility – it took the vast, tedious odyssey of the EU and reduced it to things that people could touch and feel and, more importantly, consume: beer, crisps, bananas – and its campness, the knowing way that these things were hyper-exaggerated into icons of identity. It took Europe down to microcosmic minutiae and then blew them up again into a macrocosmic tale of oppression.

But these very strengths turned against themselves at the moment of “liberation”. The tangibles crumbled at a touch – they no longer had any political meaning. And the exaggerations were instantly deflated when the context suddenly changed. They only meant anything when they were stones being thrown gleefully over the neighbour’s garden wall.

The camp, ironic discourse that underpinned Brexit was an in-joke that could not live outside the very thing it sought to subvert, the EU. It was an elaborate form of courtier’s humour – it had meaning only while there was a court to mock and fellow-courtiers to get the jokes. It worked only when Britain was in Europe – the whole joke was dependent on living a double existence, being part of the union but pretending to be on the outside, being actually in but imaginatively not of the EU. It was a drag act that suddenly had to appear in street clothes.

In Boris’s camp performance, every statement came with in-built quotation marks. It was a comedian’s catchphrase. But on June 23rd, 2016, all the quotation marks fell off. This was now supposed to be about something. The awful truth was that it simply wasn’t.

This is an edited extract from Fintan O’Toole’s Heroic Failure: Brexit and the Politics of Pain, published by Head of Zeus; Jonathan Coe reviews it here