For Jeremy Corbyn, this was the sweetest of defeats.
The Labour leader won just 262 seats, not nearly enough to secure a majority in Parliament. His party is the second largest in the House of Commons, not the first. He won fewer seats than Neil Kinnock in 1992.
And yet for Mr Corbyn this is a result that exceeded all expectations. Having begun the campaign 20 points behind in the polls, he has won an astonishing 40% of the votes. That is the largest increase in the share of the vote by a Labour leader since Clement Attlee in 1945.
As a result, Mr Corbyn won 30 more seats for his party than Ed Miliband achieved two years ago. He has deprived Theresa May of her majority. He has won seats in southern England such as Canterbury and Plymouth that for years have been Labour no-go areas.
After months of internal criticism, a man who was described as Labour's weakest leader since Michael Foot now has his position assured. He is being compared to Bernie Sanders, the populist American Democratic politician who gave Hillary Clinton a run for her money in the last presidential contest.
So bullish is the Labour leader that he is even suggesting his party could form an unlikely minority government and not the Conservatives. At the very least, he is now very much the Leader of Her Majesty's Official Opposition with real heft in the House of Commons.
Mr Corbyn was rewarded for a campaign that had an old-fashioned feel, one where he addressed large rallies and channelled a mass grassroots movement with effective party organisation. Unlike the prime minister, he engaged with the media and chose to take part in the TV debates. He showed he could learn, ditching the down-at-heel lecturer look for a more professional demeanour. He cut his hair, did up his tie and bought a proper suit.
In the face of a brutal onslaught from the print media, Mr Corbyn learned to keep his calm, realising that peevishness is seen by many voters to be an unattractive trait. In fact, he may well have benefited from the negative headlines in the Daily Mail and the Sun if they convinced wavering Labour voters to return to the fold out of tribal loyalty.
And Mr Corbyn appears to have done what few political leaders have done in recent years - he engaged with young people and convinced them to come out to vote. He did this by promising not just to cut their tuition fees - a bribe as shameless as past Tory promises to protect pensioner benefits - but also offering them some positive politics and a little passion. There was less of this on offer from the other side.
He managed to engage with voters by appearing authentic, feeling the pain of those who have endured austerity for years as real wages fell, acknowledging their belief that globalisation at times has left them behind. He showed, amazingly, that Labour did not have to move to the centre to win votes but could do so from the unashamed left.
He appealed to a coalition of young people, public sector workers and urban liberals, many of whom showed they were once again prepared to back someone who calls himself a socialist, promises to tax more and spend more, and is reluctant to deploy nuclear force. Many voters dismissed concerns about the affordability of his plans - dubbed the famous "magic money tree" by his opponents - and instead embraced the new radicalism.
Mr Corbyn has changed British politics and as such the Labour party, whose obituary was being written by some Tories before this election, is now a force to be reckoned with in this new parliament.