France's midfielder Amandine Henry celebrates Sunday. France advanced with a win over Brazil. (Loic Venance/AFP Getty)

By Liz Clarke in Le Havre, France

They were singing when they disembarked from Brazil’s team bus for Sunday’s match against France, a place in the quarterfinals of the Women’s World Cup at stake. Leading the procession was ­Marta, strumming her ukulele-like cavaquinho and looking more like the grand marshal of a joyful parade than FIFA’s six-time world player of the year.

When Brazil’s 10th-ranked ­Selecao stepped onto the field at Stade Oceane a few hours later, they carried with them that same abandon and creative spark. And for 90 minutes, it was all the heavily favored, supremely disciplined and splendidly balanced French could handle.

But after coming perilously close to getting bounced from its own tournament in the round of 16, France prevailed, 2-1, by turning back a Brazilian squad that had controlled possession, passed with more accuracy and played far more freely from the outset.

To do it, France needed extra time, several clutch defensive stands and a goal in the 107th minute, delivered by the left foot of captain Amandine Henry. Its reward is a place in the quarterfinals.

It now falls to the three-time and defending World Cup champion U.S. women to do their part to deliver the quarterfinal matchup that has been anticipated from the moment the draw was announced. With a victory over Spain on Monday in Reims, the United States will meet fourth-ranked France on Friday at Parc des Princes in Paris.

Although his team was ultimately humbled, Brazil Coach Vadao said he felt Les Bleues had a strong chance of winning their first Women’s World Cup title.

“France has everything it takes to win,” Vadao said. “Today we were sure that the team that advanced would eliminate a strong opponent, and France was able to eliminate us. Now they have a very important [quarterfinal]. But France is absolutely prepared to win this World Cup. There is no question about it.”

France has been considered the team most likely to derail the U.S. women’s hopes of defending their 2015 title. With seven starters competing for powerhouse club Olympique ­Lyonnais, France’s core has trained and played together for years. The French are balanced from back to front and have a healthy blend of experience and youth.

France entered the tournament with one unanswered question: Would the spotlight and expectation that come with playing at home inhibit its performance or elevate it?

Les Bleues answered that question emphatically in the tournament opener by routing South Korea, 4-0. And they rolled through the group stage, amassing seven goals while allowing just one — an own goal at that.

But their struggles in Sunday’s first half exposed a potential vulnerability of another sort: Trying so hard, they forget to enjoy the game. They had trouble hanging on to the ball, normally a strength, while Brazil kicked it around deftly and was far more aggressive and opportunistic in taking it away.

“The first half was very tricky, very tense, and we weren’t getting our passes right,” France Coach Corinne Diacre said. “We weren’t at our best. I felt I didn’t recognize my team out there. I told the players to start having fun out there, enjoy the game and to be a bit more patient when they were on the ball.”

After a scoreless first half in which an apparent goal by Valerie Gauvin was negated by video review that drew hisses and jeers from the crowd, France was the aggressor to start the second half. Kadidiatou Diani streaked down the right side and sent a cross that gave Gauvin her moment back, and she timed her slide perfectly to blast the ball into the net with an extended right foot, breaking the stalemate in the 52nd minute.

Brazil replied in the 63rd. Although Thaisa’s goal was initially ruled offside, VAR negated the call, and the equalizer stood.

With the score knotted at 1 after 90 minutes, they played on.

France’s Griedge Mbock Bathy made an outstanding save in the first half of extra time, rejecting a surefire goal that had slipped behind keeper Sarah Bouhaddi.

With penalty kicks looking likely, Henry volleyed a free kick by Amel Majri into the net for the game-winner. She was immediately smothered in hugs, and a capacity crowd of 23,965 that had poured its lungs and heart into the effort erupted anew.

“It is very difficult for me to talk about this now,” Henry said when asked about the sequence that led to her goal. “It wasn’t a walk in the park this evening. . . . We really fought until the very end in order to ensure we went through to the next round.”

There was no indication afterward that Sunday’s match was the final World Cup appearance for Marta or 41-year-old teammate Formiga, a midfielder who drew starting honors and was subbed out in the second half. But at 33, Marta need not play another moment to secure sports immortality.

Just 5-foot-4, she grew up playing soccer barefoot with boys in her small town. Now she enjoys cult status in Brazil and commands global respect from her peers for the inventiveness, style and quickness of her play, as well as her professionalism off the pitch.

Earlier in this tournament she became the first player to score in five Women’s World Cups. Her 17 World Cup goals are a record among men and women. And she walked off the field Sunday to deserved applause, but not before congratulating the French players.

For Marta’s individual brilliance, Brazil’s women have never won soccer’s two biggest global prizes. They finished runner-up to Germany in the 2007 World Cup, and they took Olympic silver medals in 2004 and 2008.

But Marta’s eye is on another prize as well, as she indicated afterward.

“I’m proud of our performance, the grit that we showed until the end,” she said. “That’s the feeling that I will keep with me. Those are the kind of matches that will help women’s football to continue to grow.”

In-game highlights

By Cindy Boren in Washington

France 2, Brazil 1: France came up big at the 106-minute mark with Amandine Henry putting the ball in the net from six yards out after Kadidiatou Diani had won a free-kick on the right. Amel Majri had pushed it toward the goal and Henry pounced.

Brazil had a terrific chance of its own when Debinha broke away with a clear shot at Sarah Bouhaddi earlier in extra time. But Griedge Mbock Bathy sneaked over and just managed to clear it off the goal line and the tension, if possible, continued to grow in Le Havre.

Cristiane made an extremely long kick two minutes into extra time and collapsed to the ground after grabbing her left leg. She was helped off the pitch, putting no weight at all on the leg.

France 1, Brazil 1 (end of regulation): France and Brazil head into extra time, with 33-year-old Marta remaining on the pitch in Le Havre, with the score at 1-1. Brazil has one of the oldest rosters in the World Cup; will that be a factor?

Brazil’s Tamires was all alone as she put the ball into the net at the 84-minute mark, but there was a very good reason she was all alone. She was wildly offside and humans as well as the video assistant referee concurred in a moment of rare synchronicity.

France 1, Brazil 1: Thaisa put the ball in the back of the net, although she initially appeared to be offside to the eyes of the announcers. The video assistant referee got this one right, however, and Brazil had the equalizer at 63 minutes. Suddenly it felt as it all the pressure were on France with a quarterfinal berth against either Spain or the U.S. on the line.

Brazil had come tantalizingly close, with Cristiane hitting the crossbar just after France’s goal, with Bouhaddi just getting her fingertips on the shot and helping it over and away. Play had opened up considerably, with each team’s speed on full display.

France 1, Brazil 0: Valerie Gauvin scored at the 51-minute mark, after France opened the second half with strong, focused possessions.

Diani sprinted down the right flank, feeding Gauvin and, this time, it counted for keeps.

France 0, Brazil 0 (halftime): The first half consisted of two lengthy stretches in which France and Brazil were merely feeling each other out, with a controversial middle stretch in which a goal was disallowed and Wendie Renaud of France drew a yellow card for a high hit on Devinha.

The first half was that kind of foul-palooza.

Play got a little chippy after France took the lead on a goal by Valerie Gauvin 22 minutes into the game, only to have it waved off with another controversial review that brought boos cascading down in Le Havre.

Players had collided in front of Brazilian goalie Barbara, who was hurt on the play, and Gauvin steered the ball into the net. It appeared to the video assistant referee that Gauvin took the ball out of Barbara’s hands, but she did not seem to have control. FIFA’s official take? There was a foul on the play and the goalie had possession, but the organization offered no further details.

This World Cup will be remembered as marred by VAR.

At the 15-minute mark, Devinha drilled a shot from 20 feet out, but it was knocked way by a defender. With Marta swooping in, France fended off the first pressure of the game. The tempo was brisk, but neither team mustered a serious threat over the first 22 minutes.

The pressure on France was significant and it showed in the tight first 15 minutes as each team focused on establishing its game and taking the measure of the opponent.

Pregame preview

France faced the problem of coming up with an answer for Marta, something other teams have failed to do for years, and simultaneously deal with the lofty expectations of French fans as the host country. The crowd in Le Havre left little doubt which way it’s leaning, providing a home-field advantage. But will it be enough?

France’s 7-1 goal differential in the group stage was heavily skewed by an opening 4-0 win over South Korea, which went winless in group play and only managed one goal in a meaningless finale against a Norway team already preparing for the next round. France’s other two games: a 2-1 win over Norway and a 1-0 victory over Nigeria, with both deciding goals scored on penalty kicks (the latter after being awarded a controversial second attempt).

Brazil, meanwhile, made it through perhaps the tournament’s toughest group despite coming into the tournament in dreadful form, and any team with Marta — even a 33-year-old Marta — has to be considered dangerous.

The winner will almost certainly face the United States, which plays Spain Monday, in the quarterfinals.

Knockout round history: The French have been to the quarterfinals twice and past that point just once, losing to the U.S. in the 2011 semifinals. Brazil advanced to the quarterfinals in four straight World Cups before a round-of-16 loss to Australia in 2015. The Brazilians have been to the final once, losing to Germany in 2007.

Read more World Cup coverage from The Post:

Jill Ellis sits quietly at the heart of the U.S. juggernaut in World Cup

As the U.S. storms through the Women’s World Cup, there are more boys’ faces in the crowd

Germany advances to quarterfinals for eighth straight time with a win over Nigeria

Norway beats Australia to reach quarterfinals

USWNT, USSF agree to mediation in gender-discrimination lawsuit

U.S. players keep soccer separate from lawsuit, but they’re scoring in both