Spain are aiming to become the first side to win Olympic gold after lifting the Women's World Cup, having defeated England in the final of that tournament last year.
Ballon d'Or winner Bonmati levelled after Aoba Fujino's stunning 13th-minute free-kick opener in Nantes, before the Spain midfielder teed up Mariona Caldentey's winner 16 minutes from time.
That result saw Montserrat Tome's side seize top spot in Group C ahead of Brazil, who edged past Nigeria 1-0 thanks to Gabi Nunes' first-half finish.
Elsewhere in Group A, defending champions Canada put off-field issues to one side by overcoming New Zealand 2-1 thanks to goals from Cloe Lacasse and Evelyne Viens in Saint-Etienne.
Canada's integrity had been questioned ahead of the game in the wake of a spying scandal, with assistant Andy Spence serving as head coach after Bev Priestman volunteered to sit out.
Priestman, two members of her staff and the Canadian Olympic Committee are being investigated by FIFA's disciplinary committee after a drone was spotted flying over New Zealand's training on Monday.
"Obviously the timing was quite terrible," said Canada captain Jessie Fleming of the drone incident after her side battled back following Mackenzie Barry's early opener.
"But I think for us, we've just leaned into each other as a player group and we really just want to focus on being here and playing."
Hosts France seemed on course for a routine victory in the other Group A game after Marie-Antoinette Katoto's first-half double and Kadidiatou Diani's goal against Colombia.
However, Catalina Usme pulled one back from the spot and Manuela Pavi further reduced the deficit nine minutes later, only for Mayra Ramirez's late red card to help France hold out for a 3-2 victory.
Meanwhile, Germany swept aside Australia 3-0 in Group B, inflicting the Matildas' joint-heaviest defeat at the Olympics, along with a loss against the same opponent by the same scoreline, at Sydney 2000.
Efforts from Marina Hegering, Lea Schuller and Jule Brand sealed the victory for the DFB-Frauenteam against the Tokyo 2020 semi-finalists.
Two-time runners-up Brazil were seeking their first gold and thought they had taken the lead early on at the Parc des Princes, only for Ludmila's strike to be rightly ruled out for offside.
Swanson used her pace to break clear soon after but was unable to get the better of Lorena, with neither side truly going close to finding a breakthrough in the first half.
The Selecao suffered a blow early in the second period when Vitoria Yaya was forced off the field on a stretcher and their outing soon got worse when Swanson fired home.
Chicago Red Stars forward Swanson held her line well, latched on to Korbin Albert's throughball and calmly slotted past Lorena with 57 minutes on the clock in Paris.
Brazil could have taken a game of few clear-cut chances to extra-time, but an unmarked Adriana saw her header kept out by Alyssa Naeher in stoppage time as Emma Hayes' team claimed gold.
Data Debrief: Swanson the golden girl for USA
Swanson was denied a dramatic goal on her 99th cap for the USA in their 1-0 extra-time win over Mexico in the semis, but she marked her century in the perfect manner as she scored for the fourth time this tournament.
The 26-year-old is the 44th player in USWNT history to reach that milestone and is the youngest since Amy Rodriguez (25) did so in 2012.
The USA's fifth Olympic gold, coming 12 years after their last success in London, takes them four clear of Germany, Canada and Norway as comfortably the most successful side in the competition.
Salma Paralluelo netted two late consolations, but the damage was already done as Irena Paredes' own goal, Gabi Portilho, Adriana and Kerolin denied the world champions a place in the gold-medal match.
Brazil were still without legend Marta after she lost her appeal over a two-game ban, but her team-mates ensured she would bow out of Olympics action with the chance to play for the top prize.
Spain were behind after just six minutes as Cata Coll's poor clearance struck the unfortunate Paredes on the side to send it cannoning over the line.
La Roja struggled to gain a foothold, and Brazil doubled their advantage on the stroke of half-time thanks to Portilho's composure when one-on-one with Coll.
Adriana made sure of their progress off the bench in the 71st minute – she struck the bar but was then on hand to head Portilho's nod-down in from close range.
That sparked Spain into life and Paralluelo's looping header snuck in at the far post before Alexia Putellas rattled the crossbar and forced Lorena into a smart stop to slow down the comeback attempts.
Kerolin delivered the hammer blow in the opening seconds of stoppage time by sliding her low shot through Coll's legs, though Paralluelo would have the last say, poking in her second of the match from close range in the 112th minute.
Data Debrief: World champions denied
Spain were aiming to become the first side to win Olympic gold after lifting the Women's World Cup, but they just fell short at the final hurdle after being outplayed.
La Roja's late flurry of chances meant they finished with more shots than Brazil (26 to their 17) and more on target (11 compared to seven).
Brazil's dominance showed in other ways though, as they created an expected goals (xG) of 3.27 and had a total of six big chances, as they secured a meeting with the United States in the final on Saturday.
After being found guilty of using a drone to film opponents' training at this and past tournaments, the Tokyo champions had six points deducted, while head coach Bev Priestman has been banned from all football-related activity for one year.
The Canadian Soccer Association (CSA) are considering an appeal against the decision, but those controversies were put to one side when the team took to the field.
Starting the day bottom on -3 points, Canada, led by Andy Spence, had to come from behind to beat France after Marie-Antoinette Katoto put Les Bleues ahead just before half-time.
Jessie Fleming equalised from close range in the 58th minute, but Canada fought back, with Gilles getting some help from the woodwork to secure the win.
Meanwhile, Colombia's comfortable 2-0 victory over New Zealand means they now lead Group A after two games thanks to their goal difference.
Elsewhere, in Group C, Spain booked their place in the quarter-finals with a game to spare after a 1-0 win over Nigeria.
Alexia Putellas' long-range strike maintained La Roja's perfect start to the tournament as they bid to become the first team to win Olympic gold after lifting the Women's World Cup.
In the other group game, Japan ruined the party for Marta, who made her 200th appearance for Brazil in a shock 2-1 defeat.
Despite Mina Tanaka's penalty miss in the first half, Japan launched a comeback after Jheniffer's opener, with Saki Kumagai and Momoko Tanikawa both scoring in stoppage time to move second.
The game of the day came in Group B though, as Australia edged out Zambia in an 11-goal thriller.
Barbra Banda's hat-trick gave the minnows a 5-2 lead, but they could not hold onto it as Michelle Heyman made it 6-5 in the 90th minute to snatch a win.
USA defeated Brazil 1-0 in Saturday's final at the Parc des Princes through Mallory Swanson's goal just before the hour mark.
Hayes only took over as USWNT head coach in May, after leaving her role at Chelsea, and tasted success in her first tournament in charge.
Speaking to Discovery+ at full-time as the celebrations started, Hayes said: "I'm very emotional. It's been a dream of mine.
"I have to thank my dad - he's the one who pushed me to this position, to be able to come and coach an unbelievable group of players."
Hayes' father, who she has long described as a cornerstone in her football career, passed away last year.
"I've got my dad's necklace on," Hayes said post-match. "It's got an American eagle, and he was with me today and that helped.
"The crowd were tremendous. Brazil were tremendous. I'm just speechless. I'm in shock."
The United States have now won five Olympic golds in the women's final - four more than any other nation - with this their first since 2012.
Swanson calmly converted to give USA the victory in the French capital on her landmark 100th senior appearance for her national side.
This latest triumph comes 10 games into Hayes' tenure and puts the poor showings at the 2020 Games and 2023 World Cup in the past.
"They have received me so well and taken on board everything I've asked," Hayes added. "They're tremendous people, players and role models and I love them."
Brazil have still yet to win an Olympic gold in the tournament, with this their third runners-up finish after also falling just short in 2004 and 2008.
The Brazil great made her 200th appearance for the national team in their second group-stage game, but it was marred by a late lapse in concentration that saw Japan score twice in stoppage time to win 2-1.
Jhennifer's 56th-minute goal looked set to book Brazil a place in the quarter-finals of the tournament, but instead, they slipped down to third in Group C after Saki Kumagai and Momoko Tanikawa's goals.
And with world champions Spain up next for the two-time silver medallists, Marta, who is retiring at the end of the year, noted why it is so important that they quickly put that result behind them.
"All that mattered to Japan was winning the game," Marta said. "We took our eye off the ball and that has obviously ended up costing us.
"We could have been here celebrating a win, but instead we have to remain focused. But it's not over yet. We have to give it everything as a group. That is football. Anything can happen. Nothing has been decided."
The top two teams in each of the three groups advance into the knockout rounds, along with the two best third-place sides.
While Brazil would go through as things stand, that could all change on the final day, and head coach Arthur Elias echoed Marta's call to learn from the loss.
"I need to make amends, I need to tell the players the truth, no matter if it hurts," he said. "They obviously need to reflect. But I really recognise the effort of each and every one of them."
The Selecao's all-time leading scorer with 118 goals, the 38-year-old will appear at her final tournament with her country, having announced in April she will retire from international duty at the end of the year.
Marta has already made Olympics history. In Tokyo, she became the first player - male or female - to score at five successive Games, while she was part of the side that won silver medals in 2004 and 2008.
And Elias welcomed the inclusion of the six-time FIFA World Player of the Year, who has scored four times for Orlando Pride in the NWSL this season.
"She brings a lot to the table, she's the greatest athlete of all time," he said. "She's playing well, she deserved to be on this list.
"Marta's performance, her behaviour - with or without the ball - makes all the athletes see her as an example.
"I have the challenge of finding a way of playing to maximise her game. But she knows that you can only win with everyone."
Brazil begin their campaign against Nigeria on July 25, while they will also play Japan and 2023 World Cup winners Spain in Group C.
Gabi Portilho's 82nd-minute goal proved decisive in Nantes as Brazil claimed a place in the semi-finals.
Matters could have been vastly different for France had Sakina Karchaoui converted an early penalty, but she fluffed her lines from 12 yards.
Brazil will face Spain in the last four, while the other semi-final will see Germany take on the United States.
Germany drew 0-0 with defending champions Canada after 120 minutes of action in Marseille.
But Ashley Lawrence and Adriana Leon saw their penalties saved by Ann-Katrin Berger, who subsequently stepped up to slot in the crucial spot-kick as Germany secured a 4-2 shootout victory.
Data Debrief: Quarter-final hoodoo continues for France, Germany meet the USA again
France have now been eliminated at the quarter-final stage in seven of the last eight international tournaments in which they have participated.
Meanwhile, the USA and Germany will meet again in the last four of a major tournament for the fifth time, which is two more than any other match-up in the history of the Women's World Cup and the Olympics.
The Brazil great narrowly missed Olga Carmona's head with an out-of-control attempt to reach the ball in first-half stoppage time, receiving a straight red card in what could turn out to be her final-ever Olympic game.
Brazil needed a win to secure a place in the knockout rounds, but now they face a nervous wait to see if they will be one of the two best third-place teams in the last eight – a match they would have to play without their captain.
Athenea del Castillo eventually got the breakthrough after 68 minutes, before Alexia Putellas scored in the 107th minute to ensure they stayed perfect to top the group.
It was a dominant performance by La Roja, who created an expected goals tally of 2.75 from 27 shots compared to Brazil's 0.3 from 10 efforts.
Spain will face the best third-place team from either Group A or B in the quarter-final on Saturday.
Meanwhile, Japan also secured a spot in the knockout rounds with an emphatic 3-1 victory over Nigeria.
Japan stunned Brazil in the second group game and continued their momentum by getting the job done in the first half.
Maika Hamano and Mina Tanaka put them 2-0 up before Jennifer Echegini pulled one back for Nigeria.
However, Hikaru Kitagawa's strike just before the break restored Japan's two-goal cushion and held onto that lead to set up a meeting with the winners of Group B in the next round.
Marta scored the opener from close range after nine minutes and later added a second-half strike as Brazil thrashed China 5-0 to open their campaign in Japan.
The 35-year-old made her Olympics debut back in 2004 when the Games were held in Athens.
Marta went on to score in the Beijing, London and Rio tournaments before also netting in Tokyo on Wednesday.
She is yet to win the Olympics, though, earning silver medals in 2004 and 2008.
Marta's team-mate Formiga, who is impressively still playing at 43, also broke records by playing against China.
An astonishing 25 years on from her Olympics debut in Atlanta in 1996, Formiga has become the oldest player in the history of football at the Games.
She is also the first Brazilian to compete in seven editions of the Olympics.
Next up for Brazil is a clash with Netherlands on Saturday.
Sweden had sensationally put an end to USA's 44-match unbeaten streak at the start of the women's tournament, with Megan Rapinoe admitting the beaten world champions had "played a bit tight" in a 3-0 defeat.
However, Vlatko Andonovski's side responded impressively to that setback on Saturday, thrashing New Zealand 6-1 in Saitama, in the process registering their largest margin of victory in an Olympics fixture.
Rose Lavelle and Lindsey Horan gave USA a 2-0 half-time lead, the latter on target to mark her 100th cap. Further efforts from Christen Press and Alex Morgan added to the score after the break, while they were helped out by their opponents scoring two own goals.
It is the Swedes who sit on top of the table, though, as a strong second-half performance sealed a 4-2 triumph against Australia.
Meanwhile, Banda equalled the record for most goals scored by a woman at a single Olympics, matching Christine Sinclair's tally of six for Canada at London 2012 with another treble, this time against China.
Zambia's captain scored all her country's goals in a 10-3 loss to the Netherlands in their Group F opener. She followed up with three more in a thrilling 4-4 draw on Saturday, though China's Wang Shuang went one better as she hit four in a see-saw contest.
Vivianne Miedema later moved level with Banda on six goals at this Olympics. The forward had scored four as the Dutch crushed Zambia, then managed another two in a 3-3 draw against Brazil.
Ellen White continued her impressive start to the tournament with the winner as Great Britain defeated hosts Japan 1-0 to qualify for the last eight.
Having scored twice in the opening 2-0 win over Chile, White made it 13 goals in her past 14 international outings when heading in a cross from Lucy Bronze in the 74th minute.
Also in Group E, Canada overcame Chile 2-1 thanks to a brace from Janine Beckie, putting them second in the standings ahead of a clash with Team GB to finish the round-robin stage.
USA - winners of the Olympic tournament four times previously - managed to beat the Netherlands 4-2 on penalties in their quarter-final after the game finished 2-2 at the end of extra time.
Having finished with fewer than six points in the group stage of a major event for the first time in their history, the USA knew a much-improved display was needed against a Dutch side who scored 21 times in their opening three games, the most of any women's side at a single Olympics.
They duly delivered a strong display as they twice took the lead only for Vivianne Miedema to continue her sensational form, scoring twice to cancel out goals from Samantha Mewis and Lynn Williams in an engrossing contest in Yokohama.
Megan Rapinoe swept the decisive penalty kick high into the net after Alyssa Naeher had made two stops to her right.
BRAZIL FALL SHORT AGAIN
Canada await USA after they inflicted further heartbreak on Brazil, whose wait for gold in this event goes on.
Beaten semi-finalists in Rio five years ago, Brazil were held to a 0-0 draw before suffering another defeat on penalties to the 2016 bronze medallists.
Goalkeeper Stephanie Labbe, who was injured in the closing stages of extra time, recovered to make two critical saves in the shoot-out to secure a 4-3 win.
"In the moment, it was about trusting myself, trusting my instincts, and trusting my ability to make a save," she said afterwards.
"Pain is temporary. We have our eyes on the prize."
WHITE TREBLE NOT ENOUGH AS MATILDAS WIN CLASSIC
The stand-out quarter-final took place between Australia and Great Britain, a seven-goal thriller eventually ending in a 4-3 victory for the Matildas.
Two goals from Ellen White had turned the game on its head and looked to be enough to send Hege Riise's side through, but Chelsea star Sam Kerr levelled in the 89th minute with a crisp low strike.
The contest then swung Australia's way in a dramatic minute in extra time, Mary Fowler's deflected shot finding the top corner after Caroline Weir had a penalty saved at the other end.
Kerr scored another before White completed her hat-trick with a deft header to set up a frantic finale, with Australia just holding on for a famous win.
Remarkably, they overperformed in terms of expected goals by 3.2, their highest such figure at these finals.
Australia will contest their semi-final against Sweden, who ended Japan's quest for a medal on home soil with a 3-1 victory.
Mina Tanaka cancelled out Magdalena Eriksson's sixth-minute opener, but Sweden took control in the second half through further goals from Stina Blackstenius and Kosovare Asllani.
USA bounced back from a shock 3-0 loss to Sweden in their opening game with a 6-1 win against New Zealand, but they dropped further points in the round-robin stage on Tuesday.
Previously unbeaten in 44 games before that Sweden loss, USA failed to break down Australia's defence – Alex Morgan's disallowed goal for offside the closest they came to doing so.
Mary Fowler hit the crossbar for Australia and in the end a point apiece was a fair outcome, with the Matildas also advancing to play Great Britain in the last eight.
It is the first time in history record four-time winners USWNT have finished with fewer than six points in the group stage of a major global tournament.
RAMPANT DUTCH AWAIT USA
Sweden were already assured of a place in the last eight ahead of their clash with New Zealand and saw the job through with a 2-0 win at Miyagi Stadium to finish ahead of USA.
Anna Anvegard and Madelen Janogy were on target for Sweden before half-time and they saw out a straightforward win that condemned New Zealand to a group-stage exit.
It means USA will now take on the Netherlands in the next round in what is a repeat of the 2019 Women's World Cup final. The Netherlands lost that match, but they enter this latest showdown in superb form after thrashing China 8-2 in Yokohama.
Lineth Beerensteyn, Lieke Martens and Vivianne Miedema all scored twice in the one-sided affair, while Shanice van de Sanden and Victoria Pelova were also on target.
The Netherlands' tally of 21 goals from three games is already the most scored by a team in a single women's football Olympics event, surpassing the USA's 16 from London 2012.
HOSTS JAPAN SCRAPE THROUGH
Japan did all that they could in the final round of group games by beating Chile 1-0 through a Mina Tanaka goal 13 minutes from time.
That win took the tournament hosts to four points from three games, enough to send them through as one of the best third-placed sides, along with Australia.
Already through to the quarter-finals, Great Britain snatched top spot with a late 1-1 draw against second-placed Canada in Tuesday's other Group E match.
Caroline Weir's long-range free-kick with 84 minutes played took a heavy deflection and cancelled out Adriana Leon's opener.
Brazil also booked their spot in the knockout stages thanks to Andressa's first-half free-kick in their 1-0 win against the tournament's lowest-ranked side in Zambia, who lost Lushomo Mweemba to an early red card.
The Selecao meet Canada in the quarters, while Australia await Great Britain.
The United States face Brazil in Saturday's showpiece match at the Parc des Princes in a repeat of the 2004 and 2008 finals, fixtures the US won on both occasions.
Hayes, who was appointed as Vlatko Andonovski's successor in May, has won eight of her nine games in charge (D1), scoring 19 goals and conceding just twice.
The former Chelsea head coach won her seventh WSL title in her final season with the Blues, saying her rapid transition to the international stage has been a "whirlwind".
"Going from my beloved Chelsea to the US women’s national team - what a whirlwind and what a dream all at once," Hayes said.
"To finish my time with Chelsea with another Women's Super League title and then be here competing for gold, honestly this is the stuff dreams are made of.
"I have visualised this moment so many times in my life."
Brazil are seeking their first gold in women's football at the Games, and are boosted by the return of Marta, who will play her final international match on Saturday.
The 38-year-old was shown a red card in Brazil's final group game against Spain for a high foot, resulting in her missing the quarter and semi-finals.
Marta has scored 121 goals in 203 appearances for her nation, becoming the first player to score in five straight Olympics with her brace against Japan.
“When I was a young coach assisting Vic Akers at Arsenal, we played a Women’s Cup two-legged final against Umea, the Swedish champions, and they had a young Marta,” Hayes recalled.
“I remember being on the touchline thinking, ‘Oh my goodness, who is this extraordinary player?’ To witness what she’s done on the pitch, I think she’s been more than a role model and icon, she’s been the best player.
“What she’s done for Brazil or the generation coming through, she’s been an inspiration.”
Team USA have the chance to win a first gold medal since London 2012 after winning bronze in Tokyo three years ago.
Despite winning 16 major titles during her time at Chelsea, Hayes is hungry to add to her trophy cabinet while continuing her unbeaten start in the US dugout.
"I like winning, it's part of my DNA," Hayes said. "I'm with a team that likes winning so of course our goal is to win the gold medal."
The 23-year-old's 95th-minute strike proved the decisive goal of the USWNT’s 1-0 semi-final victory against an injury-stricken Germany.
The result means new coach Emma Hayes will have the chance to go for gold in her first major tournament at the helm.
Smith dedicated her goal to the effort of the whole US squad under the ex-Chelsea boss.
"I just saw an open net in front of me and knew I had to step up in the big moment," Smith told NBC. "I felt I had to do that for this team, we've been working so hard.”