Emmanuel Macron has won the first round of the French election and far-right rival Marine Le Pen will fight him for the presidency for a second time.
"Make no mistake, nothing is decided," he told cheering supporters.
In the end, he won a convincing first-round victory, but opinion polls suggest the run-off could be much closer.
Ms Le Pen called on every non-Macron voter to join her and "put France back in order".
With 97% of results counted, Emmanuel Macron had 27.6% of the vote, Marine Le Pen 23.41% and Jean-Luc Mélenchon 21.95%.
Kingmaker on far left
Veteran far-left candidate Jean-Luc Mélenchon polled even better than five years ago and now has the unlikely role of kingmaker.
"You must not give a single vote to Marine Le Pen," he warned his supporters, but unlike other candidates, he pointedly did not back the president instead. Later in the evening, Mélenchon activists gathered outside his campaign HQ thinking he might even come second, but it was not to be.
Making up more than a fifth of the vote, Mélenchon voters could decide the final round of this election, yet many of them may just sit the second round out and abstain.
Twelve candidates were in the running, but these were the only three who polled more than 10%. Many voters appeared to embrace the idea of tactical or "useful" voting, deciding that the other nine candidates had no hope of making the run-off.
Several of the nine had little chance anyway, but the 2022 presidential election will be partly remembered for the disaster that befell the two old parties that used to run France, the Republicans and Socialists. They sank almost without trace, with Socialist Anne Hidalgo falling below 2%.
It was only a few months ago that Valérie Pécresse was still in the race for the right-wing Republicans. She performed so badly, her party could not even scrape the 5% needed to claim its election costs.
This is potentially terrible news for a party already tearing itself apart. Parties that fail to reach 5% only get €800,000 (£670,000) of their campaign funding covered by the state, and the Republicans will have paid out far more than that.
Run-off campaign starts now
A renewed battle for votes is under way. Marine Le Pen can count on supporters of Eric Zemmour, whose more hardline nationalism won him fourth place and 7%. Nationalist Nicolas Dupont-Aignan has also backed her. She can already count on an impressive 33% of the entire vote.
ANALYSIS: No walkover for Macron
Mr Macron's team is planning a series of big rallies and major TV appearances. Most of the other candidates on the left have backed him, as has Valérie Pécresse, but one-time Socialist candidate Ségolène Royal said the president now had to "earn" victory.
Ifop pollster François Dabi said his company's 51%-49% estimate for the run-off was the closest they had ever predicted. An Elabe poll put the gap at 52%-48% and an Ipsos poll suggested it was wider still.
Addressing his supporters, Mr Macron looked a relieved man and he promised to work harder than in the first part of the campaign. He had only started campaigning eight days before the vote, his mind more focused on Russia's war in Ukraine.
"When the extreme right in all its forms represents so much of our country," he said, "we cannot feel that things are going well."
He addressed Le Pen voters too: "I want to convince them in the next few days that our project answers solidly to their fears and challenges of our time."
Ms Le Pen said it was time for a "great changeover", with a fundamental choice on 24 April of two opposite views: "Either division and disorder, or a union of the French people around guaranteed social justice."
She has built her campaign around the cost-of-living crunch facing much of Europe, promising to cut taxes and waive income tax for under-30s. There has been less emphasis on nationalism, but she wants a referendum on restricting immigration, radical change to the EU and a ban on the Islamic hijab in public areas.
The campaign only sparked into life in the final fortnight, first because of the Covid pandemic and then the Russian war. But in the end, the spring sunshine meant turnout was not as low as feared, at almost 75%.
One in four young voters backed the president, although more than one in three 18-24 year-olds opted for Jean-Luc Mélenchon, according to Elabe pollsters.
Marine Le Pen performed best among 35-64 year-olds, while the president was favoured by over-65s.
It was already clear from Mr Macron's speech that he planned to target Ms Le Pen's close links with the Kremlin. Although she has condemned Vladimir Putin's war, she visited him before the previous election in 2017 and her party took out a Russian loan.
He wanted a France that made alliances with great democracies to defend itself, he said, not a state that would leave Europe and have only populists and xenophobes for allies.