Brazil have secured the gold medal for the second straight Olympic Games after defeating Spain 2-1 in the final at the Nissan Stadium.
Andre Jardine kept faith with the same Brazil line-up that overcame Mexico in the semi-final, while Real Madrid star Marco Asensio started ahead of Rafa Mir in the Spain attack.
The game was played at a lively pace in the early stages but neither side had created a clear-cut chance in the opening 20 minutes in Yokohama.
Brazil were offered the perfect chance to take the lead after being awarded a penalty in the 38th minute, but Richarlison was unable to take advantage after failing to hit the target from 12 yards.
The defending champions eventually got their reward on the stroke of halftime when Matheus Cunha slotted past Unai Simon with a clinical finish after being set-up by Dani Alves.
The Spanish opted for a double change at the start of the second half as Bryan Gil and Carlos Soler replaced Mikel Merino and Asesnio,
However, Spain got back on level terms in spectacular fashion on 60 minutes when Mikel Oyarzabal turned home Soler's cross with a superb volley at the far post.
Neither side were able to find in the remaining stages of the second half, forcing the clash into another 30 minutes of extra-time.
It was the Brazilians who regained their lead in the 108th minute thanks to a Malcom, who latched onto Antony's longball before skipping past one player before firing into the corner for the gold medal.
Click through the gallery below to see some of the top players who competed at the Olympics: