Canada came from behind to draw 2-2 with Sweden and book their spot in the quarter-finals alongside their opponents and Japan.
Sweden, who finished top of Group F, led 2-0 early on but Melissa Tancredi scored twice as Canada went through as one of the two best third-placed teams.
World champions Japan drew 0-0 with South Africa to seal their passage.
In Group G, France beat Colombia 1-0 to join the already the qualified United States, who beat North Korea 1-0.
America's Abby Wambach turned in Alex Morgan's cute pass to earn the reigning Olympic champions a straightforward win over the North Koreans, who had Choe Mi Gyong sent off late on for two bookable challenges.
France's victory over Colombia came courtesy of an early Elodie Thomas strike.
But the 2011 World Cup semi-finalists could have made the win more comfortable as they hit the woodwork several times during the first half and found Colombian keeper Sandra Sepulveda in inspired form.
Japan coach Norio Sasaki said he told his side did not push for a winner against South Africa at the Millennium Stadium so that they remained in Cardiff for the quarter-finals.
He said: "Before the match I did not tell the players to draw the game, but if we had a situation during the game... we might have some kind of an instruction to draw the game and it happened like that."
At St James' Park, Canada, who are coached by Englishman and Newcastle fan John Herdman, looked like they were heading for defeat after conceding two goals in two minutes as Sweden took control.
Marie Hammarstrom tucked in Lina Nilsson's right-wing cross after 14 minutes and then turned provider as she broke down the left and centred for Sofia Jakobsson to finish.
Canada responded just before half-time when Tancredi - now the tournament's leading scorer - converted Rhian Wilkinson's centre.
And the forward grabbed her fourth goal of the Olympics with six minutes left to send her team-mates and manager wild with delight.