LONDON — With a pre-election lead in the polls of up to 20 points, Theresa May went into Thursday's ballot confident of securing a a commanding majority in Westminster and some serious negotiating power in Brussels.

How wrong she was.

By some measures, May and the Conservative Party did not have a bad result. With more than 42 percent of the vote, a net gain of 5 percentage points on their result in 2015, the Conservatives polled their highest vote since the era of Margaret Thatcher.

The Conservatives also retain a firm grasp on much of non-London southern England. But such growth was not matched by significant gains in the number of seats which, at 318, was 8 short of the 326 needed for a majority and even further away from the 331 seats that were won by David Cameron in 2015.

The Tory problems were most visible in London, with an anti-Brexit and pro-Jeremy Corbyn wave of support sweeping through the capital.

Worryingly for a party that has spent much of the last two years inflaming Englishness, 29 of the Conservative Party's 32 losses came in England. While the party picked up a handful of seats from Labour it was still left with a net loss of 21 seats in England. Four losses to the Liberal Democrats further hampered May’s quest for a majority.

Had it not been for several gains in Scotland, and post-election support from the Democratic Unionist Party in Northern Ireland, May and her party would now be out of government.

What went wrong?

The gamble that May and her team tried to pull off was the opposite of the one that Tony Blair had taken in the 1990s.

While the Conservatives managed to hold on to much of their core territory, plus winning seats in Scotland and fending off a Liberal Democrat revival in south west England, they failed to rally enough former Labour and UKIP voters to their cause.

This was especially noticeable in the industrial and often Labour-held north, where May and her team had sought to reconnect with working-class and socially conservative voters in seats that had opted to leave the EU. Prior to the election campaign they had even consulted Labour advisor Lord Glasman about how to build bridges with working-class Britain.

In this sense, the gamble that May and her team tried to pull off was the opposite of the one that Tony Blair had taken in the 1990s. Blair had gambled that he could win over the more educated, affluent and urban middle-class while the economically left behind blue-collar workers in the industrial north had nowhere to go but stay with Labour.

Twenty years later, May and her team hoped they could win over blue-collar workers and the industrial pro-Brexit north while the urban middle classes who had turned out for Cameron would stick with them. But much like Labour, who had watched supporters drift into apathy and then switch to UKIP, May lost her gamble.

As my colleague, the pollster John Curtice, has noted, the vote for the Conservatives actually increased least in middle-class seats, rising only 2 points in seats with the largest proportions of middle-class voters. This contrasted sharply with the picture in more working-class territory where May’s party increased their vote by no fewer than 9 points.

UKIP down, Labour up

There was a swing to the Conservatives in seats that had given some of the strongest support to Brexit last June, which were also where UKIP had tended to poll strongest, such as in Boston and Skegness where there was a 6 percent swing to the Conservatives, despite UKIP leader Paul Nuttall standing as a candidate.

But this was not enough to counter losses to Labour in pro-Remain areas. In Labour-held Tory target seats such as Darlington, which stayed Labour, it was clear that the Conservative strategy had failed. Labour also captured six seats from the Scottish National Party and two from the Liberal Democrats, making the Conservative path to a majority that much narrower.

Corbyn offered a more populist message that attracted a diverse coalition of young millennials, former non-voters and ex-Liberal Democrats. According to data compiled by Sky, youth turnout is estimated to have hit 69 percent, a dramatic increase on the 43 percent in 2015 and the highest since Blair’s landslide in 1997.

Analysis of the result indicates that Labour also polled strongest in areas that saw the biggest increase in turnout. Labour also benefitted from a swing away from the Conservatives in pro-Remain areas, such as in the affluent Hampstead and Kilburn in London where there was a 12 percent swing to Corbyn’s party.

More than half of Labour’s gains arrived in areas that had voted to Remain in the EU. Crucially, Corbyn also re-mobilized Labour voters who before the campaign had looked ambivalent about whether or not they would turn up at the polling station at all. Combined, these voters helped to propel Labour to almost 40 percent of the national vote — its highest share since 2001 when Blair was leader.

Labour's surge

This all had big consequences for the Conservatives. Disproportionately high youth turnout combined with support from urban, pro-Remain liberals allowed Labour to storm through London and university towns, causing major upsets along the way by taking seats like Canterbury, Bristol North West, Battersea, Croydon Central, Cardiff North and Brighton Kemptown.

Most dramatically, Labour captured the highly affluent and traditional Tory bastion of Kensington. In seats like that one, where the former Conservative MP had been jeered at public meetings over Brexit, Corbyn hoovered up Remainers who felt not only frustrated with the result of the referendum but were also deeply angry about May’s hard stance on Brexit.

Most of these voters concluded that Tim Farron and the Liberal Democrats, who since the referendum had endured a collapse of support in the polls, were a busted flush.

Not all of the former UKIP voters defected to the Conservatives but most of them did.

Crucially, Labour also managed to defend some of its more fragile territory in areas that had voted to leave the EU and make a number of other gains. This was not all about Brexit. Clearly, Corbyn’s pledge to tackle economic injustice, push back against the banks, impose higher taxes on the wealthy and renationalize the railways resonated with Britain’s left behind.

This allowed Labour to also take a number of other seats, such as Crewe and Nantwich, Derby North, Enfield Southgate, Gower, Warrington South, Peterborough, Bedford and Weaver Vale.

UKIP, meanwhile, had a terrible night. Rather than hold onto their support, which had always looked fragile after the vote for Brexit, Paul Nuttall and his party could only watch as their voters headed back to the mainstream.

Analysis of the election result has since revealed that, on a seat-by-seat basis, UKIP’s losses were extremely closely associated with Conservative gains. It helps us to understand, for example, why in a seat like Thanet South, which Nigel Farage had unsuccessfully contested in 2015, the Conservative vote surged by nearly 13 points to surpass 50 percent while the UKIP vote slumped by over 26 points to just 6 percent.

Not all of the former UKIP voters defected to the Conservatives but most of them did. The problem for May was that when set alongside a surge in youth turnout and a strong Labour vote in some of the key marginal seats, it simply wasn’t enough.

Matthew Goodwin is professor of politics and international relations at the University of Kent and a senior fellow at Chatham House.