ByPaul Kirby,BBC News in Paris
Nobody expected this. High drama, for sure, but this was a shock.
When the graphics flashed up on all the big French channels, it was not the far right of Marine Le Pen and her young prime minister-in-waiting Jordan Bardella who were on course for victory.
It was the left who had clinched it, and Emmanuel Macron's centrists - the Ensemble alliance - had staged an unexpected comeback, pushing the far-right National Rally (RN) into third.
Jean-Luc Mélenchon, the veteran left-wing firebrand seen by his critics as an extremist, wasted no time in proclaiming victory.
"The president must call on the New Popular Front to govern," he told supporters in Stalingrad square, insisting Mr Macron had to recognise that he and his coalition had lost.
His alliance, drawn up in a hurry for President Macron's surprise election, includes his own radical France Unbowed, along with Greens, Socialists and Communists and even Trotskyists. But their victory is nowhere big enough to govern.
France is going to have a hung parliament. None of the three blocs can form an outright majority by themselves of 289 seats in the 577-seat parliament.
As soon as he had spoken, Mr Mélenchon went off to a much bigger square, Place de la République, to celebrate his success with a crowd of 8,000 people, according to police numbers.
For National Rally's supporters the champagne was fast turning flat at their celebration-gone-wrong in the Bois de Vincennes forest to the south-east of Paris.
Only a week ago all the talk had been of a possible absolute majority, and Marine Le Pen and Jordan Bardella were still talking up their chances a couple of days before the vote.
Marine Le Pen put a brave face on it. "Two years ago we had just seven MPs. Tonight RN is the first party in France in terms of MP numbers."
In the last parliament they had 88 MPs and now more than 140, so she was right. And no other party has more than 100 MPs, because the Macronists and the Popular Front are both coalitions.
Jordan Bardella complained that his party had been foiled by unnatural "alliances of dishonour", forged by a "single party" made up of the Macron camp and the left. He wasn't wrong about the unnatural alliance, but it is only a temporary one of convenience.
More than 200 candidates who saw themselves as part of a "republican front", pulled out of the second round so that a better-placed rival could stop RN winning.
Not even Marine Le Pen's younger sister, Marie-Caroline, was able to offer a glimmer of good news from her own election battle around Le Mans.
Her bid to get into parliament failed by just 225 votes, defeated by Mr Mélenchon's candidate, Elise Leboucher, after the Macron candidate dropped out.
Turnout, at 66.63%, was the highest in a parliamentary second round since 1997. Even if RN's vote held up, this time it was having to contend with non-RN votes often being used tactically to create a "barrage" or block against them.
All over France, RN was losing run-offs it needed to win.
JEAN-FRANCOIS MONIER/AFP
Some of their candidates were less than appealing.
There was the woman who promised to stop making racist jokes if she was elected in Puy-de-Dôme; and then there was the ill-equipped young man in Haute-Savoie in the south-east who took part in a TV debate with his centrist rival and made barely any sense on anything.
They both lost, but they reflected RN's big advance in rural areas.
RN scored 32% of the vote - 37% with their right-wing allies - and for more than 10 million voters a taboo has been broken.
In Meaux, east of Paris, RN won but not by much.
After casting her vote, Claudine said people she knew tended not to admit to voting RN, unless they were with close friends.
Before the projected result at 8pm, there was fevered speculation about whether President Macron would come out and speak. Word spread that he had gone into a meeting 90 minutes earlier.
Gabriel Attal, his beleaguered prime minister, eventually appeared to give the government's response.
Four weeks ago, he had sat stony-faced and arms folded opposite the president as Mr Macron revealed his election plan.
Now he announced he would be handing his boss his resignation in the morning, but he would stay on as long as duty called.
Mr Attal is supposed to fly off on Tuesday evening to a Nato meeting in Washington. It's hard to imagine him being replaced just yet.
France has entered a period of political instability with no obvious way out. There had been talk of unrest on the streets, but only a handful of incidents were reported in Paris and cities including Nantes and Lyon,
All eyes are now on the president, who will have to navigate a way out of this deadlock.
The new National Assembly is due to convene in 10 days' time, but the Paris Olympics starts on 26 July and France could do with a period of calm.
Left-leaning newspaper Libération summed up the whole night with the headline C'est Ouf.
A relief for them that voters brought RN's bid for power to a halt. But it also means in colloquial French: "It's crazy."
Europe
France
Emmanuel Macron
Marine Le Pen