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.
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.
Giulia Gwinn gave Germany the lead from the penalty spot but Alexia Putellas had a chance to send the game to extra time at the death, only to be denied by Berger.
In a very even first half, Spain failed to register a shot on target, though they had the better chances as they twice struck Berger's crossbar. Teresa Abelleira curled a free-kick against the woodwork before Aitana Bonmati rifled a powerful long-range effort off it just before the break.
Germany's attempts to play on the counterattack eventually paid off, with Cata Coll giving away a penalty when she rushed off her line, only to crash into Gwinn.
The winger stepped up to take the spot-kick that she won, sliding it into the bottom-right corner and sending the goalkeeper the wrong way.
Berger later pushed away Jenni Hermoso's tame close-range header, but Spain would get one last chance when Janina Minge tripped Lucia Garcia in the box with mere seconds remaining.
Putellas' penalty was at a comfortable height for Berger, who dived the right way and got two strong hands on the shot to ensure her team got the prize.
Data Debrief: Gwinn's winning touch
Gwinn was the biggest attacking threat for Germany in the bronze-medal match, having the most shots (two) and more touches in the box (five) than any of her team-mates.
It is the fourth Olympic bronze that Germany have won, and their first since a run of three straight between 2000 and 2008.
Meanwhile, Spain's torrid run against Germany goes on - they have never beaten Die Nationelf in their history, and their wait for a first women's football medal at the Olympic Games will continue for at least another four years.
La Roja went into the clash in Lyon having enjoyed a perfect record at the Paris Games, but were on the brink of a shock exit when Leicy Santos put Colombia 2-0 up.
Santos' goal came after Mayra Ramirez had opened the scoring for Colombia at the Groupama Stadium.
Yet Spain fought back late on, with Jenni Hermoso scoring in the 79th minute before captain Irene Paredes netted deep into injury time.
Extra time came and went, and Cata Coll proved Spain's hero with a save from Catalina Usme, while Colombia substitute Liana Salazar also missed the target.
That paved the way for Aitana Bonmati, the Ballon d'Or winner, to dispatch the winning spot-kick and tee up a meeting with France or Brazil in the last four.
Data Debrief: Spain's quality inspires fightback
Despite creating fewer expected goals (xG) than their opponents, with 1.05 to Spain’s 2.52, Colombia showed real effectiveness in taking the chances that were presented to them.
They scored close-range goals from just four shots inside the area and seven in total, while they only had eight touches in the opposition box for the entirety of the 120+ minutes.
But Spain overwhelmed Colombia as the match wore on, as evidenced by a huge gulf when it came to final third entries, with 155 for La Roja to 26 for their opponents, while they also enjoyed 46 more touches in the opposition box than their opponents.
Paredes was ultimately Spain's hero in regulation time. She has been involved in three goals in her last five games for her country (two goals and one assist), the same as in her previous 30 games in all competitions (two goals and one assist).
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.
Targeting a first medal in the event, the host nation almost suffered last-gasp heartbreak after recovering from 70-61 behind in the final quarter.
Saki Hayashi’s three-pointer put them in front by one with 16 seconds remaining, but there was still time for Belgium’s Kim Mestdagh to take aim right at the death.
However, her last-second jump shot bounced off the rim, meaning Japan go through to a last-four clash with France.
"There were so many peaks and valleys. We were hanging on to the cliff by a fingernail in the fourth quarter," coach Tom Hovasse said.
"We just came up with plays and towards the middle of the fourth quarter, we ramped up our defence and that took them out of their comfort zone.
"We believe in ourselves, and I am hoping more people outside our locker room believe in us.
"I think it is safe to say it is the biggest win in Japan basketball history."
FRANCE FEND OFF SPAIN FIGHTBACK
Japan's next opponents are France, who beat Spain 67-64 after another epic encounter.
Despite dominating most of the contest – Marine Johannes leading the way with 18 points – France appeared in danger of throwing it all away as they fell 61-60 behind.
However, they recovered to snatch victory and secure a third consecutive appearance in the last four.
Astou Ndour had 16 points in a losing cause for Spain, runners up from the Rio Games who will not be taking home a medal this time around.
SERBIA STUN CHINA
Serbia were another team to produce an inspired turnaround as they defeated China 77-70.
Bronze medallists on their debut in Rio, the European champions recovered from 58-50 down to reach their second successive semi-final at the Games.
"How many times have we done this, 20, 30 times?" said shooting guard Ana Dabovic, who claimed six assists during the game to go alongside her 13 points.
"We never quit, and we play the hardest when we are down. We showed today we can find energy.
"This is a great success for a small country. Second time at the Olympics for Serbia; second time in the semi-finals. This is great."
Jelena Brooks top-scored with 18 points for Serbia, while Sonja Vasic had 16.
SEVEN IN A ROW STILL ON
The United States remain on course for a seventh straight Olympic gold after easing to a 79-55 win over three-time silver medallists Australia.
Breanna Stewart led the way with 20 first-half points – she would finish the contest with 23 overall - as USA ran out 79-55 winners.
"I thought we came out and played inspired basketball on both sides of the ball," said coach Dawn Staley.
"We played with an incredible desire to advance and it was just contagious.
"I thought our team was focused on keeping the heat on Australia and not let them back in the game."
Team USA have not failed to win the women’s tournament at an Olympics since Barcelona in 1992.
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.”