PARIS—A coalition of leftist parties won the most seats in France’s parliamentary elections, according to projections based on ballot counts, in a stunning come-from-behind victory fueled by a groundswell of opposition to Marine Le Pen ’s anti-immigrant forces.

A projection by polling firm Elabe estimated that the New Popular Front, a coalition of parties that includes socialists, greens and far-left France Unbowed, is expected to garner between 184 and 186 seats in the 577-seat National Assembly. The party of President Emmanuel Macron and its allies won between 160 and 162, according to Elabe, while Le Pen’s National Rally and its allies scored between 141 and 143 seats.

The outcome marks a reversal of fortune for Le Pen’s anti-immigrant party, which a week ago notched an unprecedented victory in the first round of voting .

The New Popular Front and Macron’s ranks responded by agreeing to try to pool their voters by withdrawing hundreds of third-place candidates in order to set up head-to-head matchups with Le Pen candidates for the final round. The strategy, known as the “republican front,” allowed voters to coalesce around a single National Rally opponent in each of those districts.

Macron, who has vowed to remain in office until his term ends in 2027, now faces the challenge of cobbling together a government from a disparate group of parties that have little in common besides their desire to keep the far-right out of power. That scramble will unfold with less than three weeks to go before Paris hosts the 2024 Summer Olympics.


Jean-Luc Mélenchon , the firebrand founder of France Unbowed, the biggest party in the New Popular Front, delivered a barnstorming speech after the results were in, demanding the resignation of Macron’s prime minister, Gabriel Attal. He also called on Macron to give the New Popular Front a mandate to form a government and implement its agenda with uncompromising adherence to its campaign promises.

“The president must bow down and admit this defeat without trying to circumvent it in any way,” Mélenchon said.

The New Popular Front campaigned on pledges to roll back many of Macron’s economic overhauls, including his decision to raise the legal age of retirement to 64 . The leftist coalition wants to lower the retirement age to 60, reinstate a wealth tax, dole out more housing benefits and boost public-sector wages, linking them to inflation. The measures, according to an alliance estimate, will cost €100 billion in 2025, or around $108 billion, and €150 billion in 2027.

“The New Popular Front will apply its program, nothing but its program,” Mélenchon said.

The elections risk saddling France with a hung parliament at a time when Paris is under pressure to find tens of billions in budget savings. Investors already have grown more wary of holding French assets  since Macron called the snap election, driving up the government’s borrowing costs and adding to pressure on public finances.

Macron made a massive bet in calling the election, gambling that voters would rally around his party as they had in previous elections and provide a moment of national “clarification” after National Rally trounced his forces a month ago in elections for the European parliament.

Instead of bringing clarity, Macron’s maneuver has driven the country into political fog. Avoiding a hung parliament will be hard in a lower house divided in three by large blocs with diametrically opposed agendas.

Former President François Hollande, a socialist who was elected Sunday, told French TV he expected Macron to meet with the heads of the major political parties and try to find a path through territory he described as uncharted.

“The question is what role the National Assembly is willing to play or not,” Hollande said, adding: “There will perhaps be institutional innovations to imagine.”

A French official said Macron was waiting for the election’s final results before making a decision, adding that he “will ensure the sovereign choice of the French people is respected.”

Attal said he would offer his resignation to Macron on Monday.

The prime minister took solace in Macron’s pro-business party performing better than expected, though his forces still shed dozens of seats. Macron’s party finished with 245 seats in the previous parliamentary election in 2022.

“We held on. We’re standing,” he said.

The party that Macron built around the idea of technocratic competence that was “neither right, nor left” continued to hemorrhage supporters Sunday in all directions.

Pierre Monquet, a 26-year-old Parisian, said he was shocked by the outcome of the election even though he voted for the New Popular Front. Monquet said he was disappointed with Macron’s pension overhaul and his cuts to unemployment benefits after voting for him in the 2017 election that made him president.

“I regret making that choice then,” he said.

The outcome delivered a setback to Le Pen’s protégé and pick for prime minister, 28-year-old Jordan Bardella, who on Sunday castigated Macron and the leftist parties for creating an “alliance of dishonor.”

Still, Bardella ran a campaign that ultimately expanded National Rally’s share of parliamentary seats from the 89 seats it won in 2022, a sign of how the party’s strident anti-immigrant rhetoric has moved into the mainstream of public discourse.

National Rally campaigned on restricting the rights of foreign residents living legally in France and tightening access to citizenship, welfare and housing. The party aims to rewrite parts of the French constitution, abolishing the right to citizenship for the children of foreigners who are born in France. It also wants to bar women from wearing Muslim headscarves in any public space, including the sidewalks of Paris, though Bardella has recently said the stance won’t be a priority.

“The tide is rising. It hasn’t risen high enough, but it’s still rising,” Le Pen said on Sunday. “It’s a deferred victory.”

Nicolas Duchemin, who works for a pharmaceutical company, said he held his nose in casting a vote for Macron’s candidate on Sunday in the upscale 16th district of Paris. The only other candidate on the ballot was allied with National Rally, which he absolutely opposes.

“I’m not happy about it,” he said, “because it does mean on certain occasions voting for someone you don’t trust or believe in.”

Write to Stacy Meichtry at Stacy.Meichtry@wsj.com and Noemie Bisserbe at noemie.bisserbe@wsj.com