Mr. Macron, 39, who has never held elected office, will be the youngest president in the 59-year history of France’s Fifth Republic after leading an improbable campaign that swept aside France’s establishment political parties.

The election was watched around the world for magnifying many of the broader tensions rippling through Western democracies, including the United States: populist anger at the political mainstream, economic insecurity among middle-class voters and rising resentment toward immigrants.

Mr. Macron’s victory offered significant relief to the European Union, which Ms. Le Pen had threatened to leave. His platform to loosen labor rules, make France more competitive globally and deepen ties with the European Union is also likely to reassure a global financial market that was jittery at the prospect of a Le Pen victory.

Her loss provided further signs that the populist wave that swept Britain out of the European Union and Donald J. Trump into the White House may have crested in Europe, for now.

“I understand the divisions of our country that have led some to vote for extremists,” Mr. Macron said after the vote. “I understand the anger, the anxiety, the doubts that a great part among us have also expressed.”

Mr. Macron pledged to do all he could in his five-year term to bring France together. “I will do everything I can in the coming five years to make sure you never have a reason to vote for extremism again,” he said later Sunday evening, standing before the glass pyramid in front of the Louvre, once the main residence of France’s kings, as thousands of flag-waving supporters gathered in the courtyard to celebrate.

But the election results showed that many people chose not to vote for either candidate, signaling skepticism about his project. And Mr. Macron quickly made clear that he understood the magnitude of the task before him after an often angry campaign.

“It is my responsibility to hear and protect the most fragile,” he said.

With nearly 100 percent of the vote counted, Mr. Macron had 66 percent, compared with 34 percent for Ms. Le Pen, according to the official count from the Interior Ministry.

The outcome was a watershed for Ms. Le Pen’s party, the far-right National Front, giving it new legitimacy even though the results showed that the party remains anathema to much of the French electorate for its history of anti-Semitism, racism and Nazi nostalgia.

As significant for France and for Mr. Macron’s future, nearly 34 percent of eligible voters did not cast a ballot or cast a blank or null one, suggesting that a large number of people could not bring themselves to vote for him. The abstention rate was the highest since 1969.

That lack of support presaged a difficult road ahead as Mr. Macron tries to build a legislative majority to push through his program. French parliamentary elections are next month. Currently, he has no party in Parliament.

Among the odds stacked against Mr. Macron, a former economy minister in the departing Socialist government, are deep doubts about the merits of a market economy.

“We saw the emergence of very strong anticapitalist forces,” said Gaspard Koenig, the director of the French think tank Generation Libre.

“You have 50 percent of the electorate that reject the market economy in a very radical way,” Mr. Koenig added. “Thus, he must during the next five years convince people that there are alternatives to the destruction of capitalism that can help them.”

The runoff election was groundbreaking for being a choice between two political outsiders, as well as for its rancor and for an apparent attempt to sway the vote with the hacking of Macron campaign emails, similar to the attack directed at last year’s election in the United States.

Ms. Le Pen, 48, conceded the election not long after polls closed in France, saying voters had chosen “continuity,” denying Mr. Macron his outsider status and linking him to the departing Socialists.

The vote was a record for the National Front and, she said, a mandate for it to become a new “patriotic and republican alliance” that would be “the primary opposition force against the new president.”

Ms. Le Pen earned 10.6 million votes, close to twice the number her father, Jean-Marie Le Pen, received when he ran a losing presidential campaign against Jacques Chirac in 2002. The 34 percent of the vote Ms. Le Pen won was the highest share the French had ever given to her party.

The election was also the first in which the National Front candidate — rather than being a pariah who was shut out of debates and kept off the front pages of major newspapers, as happened in 2002 — was treated more like a normal candidate despite the party’s anti-Semitic and racist roots.

After taking over the party leadership in 2011, Ms. Le Pen worked to distance the National Front from her father, its founder. Stéphane Ravier, a National Front senator and a close adviser to Ms. Le Pen, said the party needed to go further in remaking its identity.

“We will need to make some changes, do things differently,” he said in an interview as the returns came in. “We will have to talk about our positions on the euro with more pedagogy. We may also have to change the name of the party.”

In her concession speech, Ms. Le Pen acknowledged that the party had to “profoundly” renew itself to become a “new political force.”

Ms. Le Pen clearly failed to persuade enough voters that her party had sufficiently changed. Many of the votes Mr. Macron received on Sunday were no doubt cast less in support of him than in rejection of her. Nearly the entire political establishment spoke out against a Le Pen presidency.

Mr. Macron formed his political movement, En Marche! (Onward!), a little more than a year ago. He was initially given a slim chance of winning in a country that has never elected a president from outside the traditional left-wing or right-wing parties, with the exception of Valéry Giscard d’Estaing, a centrist who led from 1974 to 1981.

Since then, French politics has been dominated by the Socialists on the left and the Republicans (or their precursors) on the right.

Mr. Macron’s campaign benefited from canny timing and no small dose of luck, with the collapse of the governing Socialist Party under President François Hollande, the incumbent, who was so unpopular that he took the extraordinary step of not seeking re-election.

Mr. Macron was also helped by an embezzlement scandal that damaged the candidacy of the center-right candidate François Fillon, who, at the start of the campaign, seemed certain to claim the presidency.

Mr. Macron’s message — that his new movement was neither right nor left, but represented a third way, with elements of both — seemed to appeal to numerous urban voters, as well as to many young voters.

As the results appeared on a screen set up at the Louvre, Macron supporters shouted with joy. Some started singing the Marseillaise, the French national anthem.

“This is a historic moment,” said Jacques Pupponi, 60, who came with his children: Noé, 11; Dora, 12; and Eden, 13.

“I’ve lived moments like this before, in 1981,” he added, referring to the election of the Socialist president François Mitterrand. “I’m very happy about the score — it’s very, very important,” Mr. Pupponi said of Mr. Macron’s decisive victory.

For Mourad Djebali, 30, a Tunisian engineer who obtained French citizenship a few months ago, the result felt like a personal affirmation. “I’m moved,” Mr. Djebali said. “I recognize the France that has received me.

“It’s a great symbol of France,” he added. “It’s a sign of hope. Everyone doesn’t agree with each other, but that one thing we agree on is that we should not open the door to the extremes.”