As they awaited the exit poll at 10pm on election night, neither Boris Johnson, nor Jeremy Corbyn, foresaw the scale of the Conservatives’ triumph. Until the last moment, Corbyn and his team continued to hold out hope of a hung parliament. Johnson, meanwhile, reportedly expected a majority close to 10 seats. He ultimately secured one of 80, the Conservatives’ largest victory since 1987, as Labour endured its worst defeat since 1935.

And yet as surprising as this result may appear, the clues were there throughout the campaign. Most opinion polls consistently gave the Conservatives a comfortable lead and, even more tellingly, Labour canvassers spoke frequently of the hostility they attracted.

At a Momentum activist training session I attended on 21 November, members were invited to “start shouting out the things that you’re worried about coming up”. The answers were swift: “Anti-Semitism, tactical voting for the Lib Dems in Tory areas, magic money tree, IRA, racism, position on Brexit, going backwards to the 1970s, high taxes. Momentum, people hate, people don’t like Momentum. Immigration, Corbyn not being a leader, economic impact of a four-day week.”

As I noted at the time, “successful political movements identify their vulnerabilities and work ruthlessly to neutralise them. But that Momentum activists can readily name so many perhaps augurs less well.”

Lynton Crosby, the former Conservative campaign manager, is fond of remarking that “you can’t fatten a pig on market day”. Political strength must be honed long in advance of an election, not during it. Labour entered the campaign with far too many weaknesses to ever have any hope of supplanting the Conservatives.

Foremost among these was Jeremy Corbyn’s unpopularity - the worst ratings of any opposition leader in polling history (a net rating of -60 in an Ipsos MORI survey). In an increasingly presidential system, leaders matter. A post-election Opinium survey found that 43 per cent of those who did not vote Labour cited its leadership, compared to 17 per cent for its stance on Brexit and 12 per cent for its economic policies.

Corbyn’s unpopularity had many facets: he was never trusted to manage national security (his response to the Salisbury poisoning did particular damage) or the economy, and even polled behind Johnson on public services. He presided over a permanently divided party, many of whose MPs never regarded him as fit to be prime minister, the scandal of anti-Semitism wounded his claim to moral authority, and his equivocation on Brexit undermined his promise of “straight-talking, honest politics”.

Some of this can be attributed to the relentlessly unfavourable coverage of Corbyn by pro-Conservative newspapers. But a politician complaining about the media is akin to a sailor complaining about the sea. Rather than lamenting the waves, one must ride them. And far from doing so, Corbyn frequently walked head-first into them.

Labour’s belated support for a second Brexit referendum is being blamed by many for the loss of Leave seats. But the party did not only lose votes to the pro-Brexit Conservatives (to whom nine per cent of its 2017 coalition defected), it lost an equal share of votes to the pro-Remain Liberal Democrats and Greens (who split the vote in some Leave seats).

In different respects, Labour’s ambiguous Brexit policy managed to alienate Leavers, Remainers and those in between. There is no way of knowing how voters would have responded to a more unambiguous stance. But what we can say with certainty is that Corbyn’s neutrality appeared an act of evasive weakness, rather than one of strength.

Labour’s individual policies, as Corbyn and John McDonnell have been swift to point out, were often highly popular. As I noted in 2018, for instance, a poll published by the Legatum Institute and Populus found that voters supported public ownership of the UK’s water (83 per cent), electricity (77 per cent), gas (77 per cent) and railways (76 per cent). Around two-thirds of voters supported policies such as higher taxation of top-earners, increased workers’ rights and a £10 minimum wage.

But individually popular policies are worthless unless the public accept the collective programme. In Labour’s case, they did not believe the party had the capacity to deliver its cornucopia of promises. Indeed, as Labour added pledges such as a four-day week, free universal broadband and £58bn of compensation for WASPI women, they were bewildered by its seemingly bottomless generosity.

The Conservatives, by contrast, benefited from a deliberately streamlined programme which promised higher public spending in the areas of greatest concern to voters (health, policing and schools). Above all, their promise to “get Brexit done” had a seductive appeal to both Leavers and weary former Remainers.

Whenever Labour has won decisive victories in the past, as in 1945, 1966 and 1997, it has had a compelling national story. Though the party’s promise to “rebuild Britain” after a decade of austerity hinted at such a narrative, this was never developed with the consistency required - and Corbyn and the party were never regarded as credible messengers.

Yet remarkable as it may seem, Labour has cause to be grateful that the defeat was not worse. As recently as September, having grievously alienated Remainers and Leavers, the party was polling as low as 22 per cent. The Liberal Democrats and Change UK, both of whom aspired to supplant Labour as the main opposition party, made avoidable and self-inflicted errors.

As in 1935 and 1983, Labour has suffered a near-death experience rather than simple death. The party holds 202 seats, more than the Conservatives had at any point from 1997-2010. The Tories, whose very survival was doubted after New Labour’s triumph, have since won four consecutive general elections. To paraphrase Adam Smith, there is much ruin in a party.

But this should not detract from the epic task facing Labour. The Conservatives will seek to use their victory to ruthlessly entrench themselves in power by wooing former Labour voters with higher public spending and by reshaping electoral and constitutional law in their favour (voter ID laws, boundary changes, the abolition of the Fixed-term Parliaments Act, curbs on the judiciary and the House of Lords). Labour is currently 124 seats short of a parliamentary majority (326) and Scottish independence could yet deprive it of its largest potential partner in a hung parliament.

The next Labour leader will need to be popular in the country, rather than merely within the party, and propose a programme that is regarded as credible as well as radical. Corbyn and McDonnell can reasonably take credit for forcing the Conservatives to break with austerity and for widening the Overton window - the spectrum of policies deemed acceptable by voters and the political class. But as Labour will now have ample time to rue, it cannot hope to address the climate crisis, income inequality and the degradation of the public realm from opposition, rather than from government.

The Conservatives, now perhaps the most successful political party in the democratic world, won by learning swiftly from their shortcomings in 2017. But this was still more a tale of Labour failure than Tory success. The opposition’s vote fell by 8 per cent, while the former’s rose by just 1 per cent. If there is any consolation for Labour it is that its fate, to a significant degree, still rests in its own hands. Through pessimism of the intellect and optimism of the will, the party can yet remake itself once more.