Defending champions Brazil eased through to the quarter-finals of the men's Olympic football, but 2016 silver medallists Germany are eliminated.
Everton striker Richarlison scored two late goals as Brazil beat Saudi Arabia 3-1 to finish top of Group D, with Ivory Coast second after holding Germany to a 1-1 draw.
In Group B, South Korea beat Honduras 6-0 to qualify as group winners.
New Zealand drew 0-0 with Romania to finish second on goal difference.
Brazil looked set to be held to a frustrating draw when a header from Saudi Arabia defender Abdulelah Al-Amri cancelled out Matheus Cunha's early opener at the Saitama Stadium.
However Richarlison, who hit a hat-trick in Brazil's opening group game against Germany, edged them ahead again with 14 minutes remaining before sealing the win in stoppage-time.
Germany needed to beat Ivory Coast to make it through, but fell behind midway through the second half when Benjamin Henrichs put the ball into his own net while attempting a tackle in the six-yard box.
Eduard Loewen levelled with a free-kick six minutes later to set up a frantic finish, but despite piling on the pressure Germany could not find a winner.
All four teams in Group B went into the final round of games level on three points each, but it was South Korea who progressed as group winners as a hat-trick from Hwang Ui-jo helped secure a 6-0 win over Honduras, with New Zealand joining them in the quarter-finals.
Source: BBC