Jeremy Corbyn and Labour were written off by most observers when Theresa May called the snap election with most expecting the British prime minister's big gamble to pay out handsomely with a massive House of Commons majority for the Conservatives.
After dire local election results for Labour at the beginning of the campaign, those predictions appeared to be ringing true.
But Labour's turnaround came in a dramatic week in which the party's draft manifesto was leaked to the press, then the actual manifesto was released, and which culminated in Mrs May's disastrous launch of the Tories' policy programme.
The public appeared to warm to popular Labour policies such as nationalising key industries, spending more on the NHS and education, abolishing university tuition fees, and taxing the top 5% of earners and getting big corporations to pay for it.
But Mr Corbyn still appeared to be lagging behind Mrs May on the key question of who voters thought was the best leader, until the prime minister made plans for a so-called "dementia tax" central to her manifesto pitch, before u-turning on the policy.
As the Tories found themselves in turmoil, Mr Corbyn was able to deliver impassioned speeches to ever-growing rallies with a razor sharp focus on key Labour policies, hope and unity, while attacking those put forward by Mrs May.
The Saturday following manifesto week, the Labour leader held huge and raucous rallies in Birmingham and in front of around 5,000 people on the beach in West Kirby, in the ultra-marginal Wirral West constituency of Merseyside.
That speech was followed by a surprise appearance at a music festival at Tranmere Rovers' Prenton Park stadium, where a 20,000-strong crowd who had paid to see British band The Libertines broke out into spontaneous "oh Jeremy Corbyn" chants, which then became the theme music of his campaign.
The terror attack at Manchester Arena and subsequent pause in campaigning might have halted Mr Corbyn's momentum, but a controversial and apparently risky speech on returning to the fray, linking the UK's foreign policy with the domestic terror threat, appeared to go down well with some voters.
A decent performance in front of a studio audience and the successful disarming of Jeremy Paxman in a Sky/Channel 4 live TV event was then followed by a shock last minute move to appear in a seven-way BBC election debate which was not attended by Mrs May, in an attempt to make the Tory leader appear too "frit" to face her rival.
Two days later in a BBC Question Time special, Mr Corbyn found himself on a sticky wicket when pressed on whether he would press the nuclear button, one of the most difficult moments of his campaign.
While some observers believed his honesty may have won over voters - he opposes the renewal of the Trident nuclear deterrent while official Labour policy is to support it - voter concern over his record on security issues may have hindered the party's chances of winning a majority.
After another atrocity at London Bridge provoked a pause in campaigning, the focus of the final days of the election was inevitably on security, seen as a weak point for Mr Corbyn.
But while many voters appear to have doubted his ability to keep the UK safe, his attacks on Mrs May's record of presiding over cuts in police officer numbers while home secretary appeared to get cut through.
If early reports are true and young voters did turn out in record numbers to vote Labour, it appears that Mr Corbyn's expensive pledge to scrap tuition fees may have been the key to confounding his critics - potentially alongside the backing of grime luminaries like Stormzy, appearances on the covers of NME and Kerrang, and his decision to join a busker for a rendition of Stand By Me after a stump speech in Ashton-under-Lyne in Greater Manchester.