BERLIN (Reuters) - Europe's political establishment entered 2017 in a state of panic. Britain had voted to leave the European Union six months before and the United States had just elected a president who was hostile to their grand project and the values it stood for.
The same forces that had led to Brexit and Donald Trump - popular anger with distant elites, economic inequality and immigration - threatened to hit the continent hard in a year in which Europe's largest countries were holding elections.
The biggest risk of all was France, a country with an ailing economy, historic ambivalence toward the EU and a politician, in National Front leader Marine Le Pen, who seemed well positioned to seize on voter fears.
Instead, on Sunday, Le Pen was soundly defeated by Emmanuel Macron, a 39-year-old independent who ran on an unashamedly pro-European platform.
Macron urged the French to embrace rather than reject globalization. And he vowed to work with Germany to relaunch the European Union, a project long seen as a guarantor of peace and prosperity but one which is now struggling to find its "raison d'etre" after years of crisis.
Macron's victory represents a reprieve for Europe and the liberal democratic values for which it has stood for more than half a century.
The nightmare scenarios that were whispered about in European capitals in early 2017 have not materialized. Europe has been given another chance. Those are the main messages from Macron's victory and they were reflected in the reactions from Europe on Sunday.
"Hurrah Macron President! There is hope for Europe!" Italian Prime Minister Paolo Gentiloni tweeted.
German Chancellor Angela Merkel's spokesman called it a victory for a "strong united Europe" and for German-French friendship.
But the French vote was also a warning. Le Pen's National Front won 35 percent of the vote, nearly double what her father Jean-Marie secured in 2002, a result which hit the nation like an earthquake at the time, triggering a broad "Republican front" to block him.
In this election the sense of shock and anti-Le Pen front proved far weaker. On Sunday night she took to a stage in Paris and called on "all patriots" to join her in opposition to the new president.
Nigel Farage, former leader of Britain's UKIP party and a leading campaigner for Brexit, said what many in Europe may be thinking when Sunday night celebrations wear off: "If Marine sticks in there, she can win in 2022."
Macron and his fellow European leaders face a formidable challenge over the next five years to prevent that from happening.
For his part, Macron must unite a deeply divided country and deliver on his promise to inject new life into its moribund economy by delivering jobs for young people and hope for the immigrants in depressed working class suburbs around France's major cities.
Former U.S. president Barack Obama who openly backed Macron last week and whose message of hope served as a model for the French candidate is a cautionary tale for what can happen when some promises go unfulfilled.
"Macron has 12 to 15 months to take the necessary decisions so that the benefits are visible before the end of his term," said a senior German official who requested anonymity.
At the European level, he must convince German Chancellor Angela Merkel - who looks on track to win re-election in September after another strong performance by her conservatives in a regional vote on Sunday - to develop a common vision for taking Europe forward.
The good news is that Macron and Merkel are likely to have other like-minded leaders to work with. Mark Rutte, the liberal prime minister of the Netherlands, fended off a challenge from far-right Freedom Party leader Geert Wilders in an election in March.
And next year may see the return of another young pro-European centrist in Matteo Renzi, who was forced to resign as Italian prime minister in December, but now looks on course for a comeback after regaining the leadership of his Democratic Party (PD) in a primary vote last week.
"Hard to overemphasize how much this will change the narrative about the EU. No longer the world's sick man," tweeted Nicolas Veron, an economist at Brussels think tank Bruegel.
Still, the anti-establishment wave seems unlikely to disappear anytime soon. In Poland and Hungary, right-wing governments are already flouting EU rules.
And opposition politicians like Le Pen and Wilders have gained a stronger platform from which to promote their messages.
They may also learn lessons from their recent defeats.
Le Pen said on Sunday that the National Front would be completely overhauled. Her deputy said the party would get a new name. And her father Jean-Marie said her campaign had been undermined by its proposals to quit the euro and the European Union, suggesting they might temper policies that spooked many French voters.
"Even if the globalists have won today, it doesn't mean that the populists won't win tomorrow," said Daniele Antonucci of Morgan Stanley.
Reporting by European bureaus; writing by Noah Barkin; editing by Philippa Fletcher and Richard Balmforth