They came from every corner of Britain to help secure victory. From Scotland to the South West, hundreds of budding Conservatives flocked to West Yorkshire over the past month as the party threw everything at the Batley and Spen by-election, confident that it could oust Labour in the northern constituency for the first time since 1997. It failed, albeit by just 323 votes.

Privately, the Tory party believed it would win. But those on the campaign trail in the former mill and mining seat were not so sure. “Our candidate did well in quite a toxic campaign so his reputation is intact, but I’m not sure our party played the expectations game well enough in a uniquely difficult seat,” said Lauren McEvatt, a Tory activist and former government adviser.

Sectarianism, homophobia, bullying and sexism were all found on the streets of Batley in the nastiest by-election the UK has seen in decades. Many of the tensions were due to the divisive presence of leftwing agitator George Galloway, who came third with 21 per cent of the vote. But Labour’s candidate, Kim Leadbeater, calmly battled her way through the tensions to become the new MP.

The victory is a huge relief for Keir Starmer, the Labour party leader. Had people voted differently, he could be facing a leadership challenge. Instead he gained some much-needed momentum.

One young Labour activist cautioned that local factors may be behind the party’s success. “Almost everywhere we went, the line people were coming back with was, ‘I’m voting for Kim’, and the motivations were anti-Tory, anti-Galloway or pro-Kim and not really reflective of any genuine affinity with Labour.” Leadbeater also has a strong emotional connection to the seat: her sister Jo Cox served as its MP and was murdered there in 2016.

But Batley and Spen offers several national political lessons.

For the Conservatives, the result highlights a number of problems. First, a growing arrogance. After the party’s thumping win in Hartlepool in May, many assumed that it was on course to win in Batley and Spen as well, despite the fact that the constituency’s diverse demographics and lack of a local base made it unnatural territory.

The Tories might have done better to consider Chesham and Amersham — another by-election failure in May, this one in leafy Buckinghamshire. One activist said, “we are forgetting who our voters are. We are fundamentally misunderstanding the issues; on rural matters, on bins, on things that have brought the vote home over the last 120 years.”

The Batley and Spen result also revealed Tory complacency. Boris Johnson won the 2019 election by promising to deliver Brexit and improve the lot of England’s working classes. He has attempted to hold on to these voters with a populist governing style and a leftward shift on economics. But his party has been in power for a decade and his delay in sacking Matt Hancock, the former health secretary who broke lockdown rules during an affair with an aide, was seen by many as a sign the party was disregarding its supporters.

“That campaign was lost in the three days of chaos over Hancock. Why did Boris not grasp how damaging it would be and sack him immediately?” one activist sighed.

The Hancock affair has also given Starmer a strong narrative for critiquing the Tories. “We got a lot of ‘one rule for them one for the rest of us’ stuff, ” one Labour activist said of the final days of campaigning. This could be a rich seam for the party to mine in the future.

With two by-election losses under his belt, Johnson is no longer seen as infallible. Chris Curtis, senior research manager at the pollsters Opinium, reckons Labour’s Batley and Spen win would have been unsurprising in more usual political times. “It is what you would have expected given national polls if you add a bit on to Labour — for the opposition always do a bit better in by-elections.”

As coronavirus no longer dominates the UK’s discourse, the Tories cannot rely on the success of the vaccine programme to mask the government’s missteps and failings. Batley and Spen suggests that after the oddest of years, political normality is returning to Britain.