The Labour leader started this campaign with a deficit in the polls of around 20 points, and his chances written off by most experts, political commentators and the press. Even many of his own MPs -- some of whom tried to unseat him last summer -- didn't think he had it in him to be Prime Minister.
The result is not yet final and it still looks like May's Conservatives will still have the most seats, meaning they will be able to start talks to form a coalition. But the fact that Corbyn is expected to have robbed May of her overall majority is a significant endorsement from voters for his brand of left-wing, populist politics. The fact that he has defied all expectations and caused a major electoral shock will draw comparisons with Donald Trump's surprise victory.
Like the president, the Labour leader is anti-establishment, unconventional and populist. The difference is Corbyn is on the left-wing of the Labour party -- far to the left of its former leader and Prime Minister Tony Blair. It remains unlikely that Corbyn will be Prime Minister, but he has scored a moral victory over his critics in parliament, his own party and the press.
His manifesto -- a raft of leftwing policies with renationalization of industry at their core -- has been well received by voters. Stories about Corbyn's past support for the Irish Republican Army and Hamas are failing to inflict serious damage. And in the wake of the suicide bombing in Manchester and the attack on London Bridge,
the Labour leader's perceived weakness on security and counter-terrorism don't seem to have damaged him in the court of public opinion.
At the start of the campaign in April, the Prime Minister set down a narrative that the June 8 election was a choice between her "strong and stable" leadership that would deliver a successful Brexit,
and Corbyn's far-left brand of Labour.
But as the votes are counted, it is remarkable how Corbyn has managed to change the narrative and turn the election into a competitive fight.
This shift has been achieved, say commentators, in part because Corbyn does not behave like an ordinary politician. While other party leaders adapt their policies to the changing times, his views -- including opposition to Britain's independent nuclear deterrent, and in favor of higher taxes on the rich to pay for healthcare and schools -- have not changed in more than 30 years.
From trade unionist to politician
Corbyn was raised in rural Shropshire in central England and was educated at a local grammar school before studying at a North London college, from where he left after one year, failing to finish a degree. After working for a number of trade unions he got his first break in politics at the age of 25 when he was elected to a council seat in Haringey, a borough in north London.
Nine years later he became Labour MP for the London seat of Islington North, at the same time Tony Blair entered Parliament. Their career paths could not have been more different: while Blair rose through the Labour Party to become its leader in 1994 and prime minister in 1997, Corbyn remained a backbench MP, rebelling against Blair in hundreds of votes in the House of Commons and most prominently as a vocal critic of the Iraq war.
It was after Labour's second electoral defeat in a row, in 2015, that Corbyn's name was put forward for the leadership contest as a "token" leftwinger, but was at first not taken seriously. He went on to win
with nearly 60% of the vote.
In the same way Bernie Sanders experienced an insurgent tide of popularity from younger voters, 68-year-old Corbyn is most popular among 18-34 year-olds.
The success of Corbyn's anti-establishment pitch -- he saw off a challenge from the party's centrists in 2016 -- may also invite comparisons with the US president. Like Trump, the Labour leader is prone to outbursts of tetchy, erratic and stubborn behavior.
By coincidence, Trump and Corbyn have each been married three times. Yet the similarities perhaps end there: Corbyn has the unassuming manner and bearing of a high school science teacher and likes to spend his weekends on his community garden plot, not playing a round of golf in a lavish hotel resort.
"There is a certain freshness about the Corbyn campaign which is attractive to people who are fed up with the staleness and tiredness of political discourse," says Tom Baldwin, who was director of communications for the previous Labour leader Ed Miliband at the 2015 election. "Corbyn himself doesn't look scared in interviews. He doesn't look scared of being found out."
"He has a really thick skin and he is very comfortable in it. As such there is an 'x-factor' to him which it would be churlish not to acknowledge."
Race to the finish
In the past two weeks, newspapers have highlighted Corbyn's links to the IRA and Hamas, including his appearances at events commemorating both organizations. But voters appear to be unmoved.
Baldwin says Corbyn has benefited from an absence of the kind of intense scrutiny normally applied to potential prime ministers because, unlike Miliband in 2015, "at the start of this campaign everyone thought Corbyn had a cat in hell's chance of winning". Opponents had not really had a chance to hone their attacks on Corbyn until now, he added.
But according to Baldwin, the narrowing in the polls is more as a result of failings in the Conservative campaign, including pinning so much on May as a "strong and stable" leader, which backfired because she was forced to perform a u-turn over a major policy on funding for elderly care. There has also been little effect in the polls from her position as an authoritarian, security-minded prime minister in the wake of the Manchester and London attacks.
"The Tories have been running a terrible campaign - that is the single most important factor in this election so far," says Baldwin. "They dropped the ball and it is very difficult to turn their line around. They have tried to make this all about her and have managed to tarnish her brand in the course of three weeks."
Now it is Corbyn, in his refusal to budge from his old fashioned brand of leftwing politics -- and perhaps because expectations of him, as the underdog, were already low -- who now appears to represent stability.
While it remains unlikely he will be prime minister, the Labour leader has turned the most predictable election in recent British political history into an unexpectedly dramatic race to the finish.