PARIS — President Emmanuel Macron of France lost his bet that he would defeat the far right, not only losing the election to the European Parliament but getting beaten by the populist firebrand he roundly defeated only two years ago, Marine Le Pen.

Even so, it was mostly smiles in the presidential camp on Monday, with upbeat talk of staying the course in domestic policy and satisfied appraisals that the worst had been avoided in Mr. Macron’s party’s relatively narrow loss to Ms. Le Pen’s National Front, now rebranded as National Rally.

That confidence, characteristic of a president only rarely subject to self doubt, could spell trouble down the road, though, in the view of many analysts. On Sunday, the president lost the disgruntled France that spawned the Yellow Vest movement, and those grievances have not disappeared, as the vote for the European Parliament demonstrated.

“There’s a split between the two Frances,” said Jean Garrigues, a political historian at the University of Orleans, between Mr. Macron’s France, “and peripheral France, which considers itself a victim of globalization.”