Brazil defended their Olympic title at Tokyo 2020 after they edged out Spain by 2-1 in extra-time during the men's gold medal match at International Stadium Yokohama on Saturday.
Matheus Cunha's first-half finish was cancelled out by Mikel Oyarzabal's volley on the hour-mark in Kanagawa Prefecture, forcing an additional half-hour between the Selecao and La Rojita.
Former Barcelona star Malcom proved to be the hero for Brazil as he bundled home a dramatic winner 12 minutes from time.
Spain, with the likes of Real Madrid playmaker Marco Asensio and Barcelona midfielder Pedri pulling the strings, started lively enough and looked to get on the front foot.
They were, however, stunned by a contentious penalty call in the closing stages of the first half.
Cunha collided with Unai Simon when competing with a cross whipped into the box, with a free-kick initially awarded against the Brazilian.
The match officials were, however, encouraged to review said incident on a pitchside monitor, with Australian referee Chris Beath deciding that a spot-kick should be the eventual outcome.
Everton forward Richarlison stepped up to take and, after a staggered run up, blazed his effort high over the crossbar.
Brazil were, however, to get their noses in front two minutes into stoppage-time when Dani Alves kept the ball alive at the back post and Cunha produce a composed finish after slipping between two defenders with a cushioned touch off his chest.
Spain made changes at the interval and found a way back into the game just past the hour mark when Oyarzabal struck a stunning volley.
He was picked out at the back post after escaping his marker and sent an acrobatic scissor kick fizzing into the net.
Brazil regained control from that point and always looked the more likely to find a winner - with Richarlison hitting the woodwork at one stage
They had to be patient, though, and were in danger of seeing the contest settled from 12 yards when Malcom made his decisive contribution.
The 24-year-old, who is now with Russian giants Zenit, stepped off the bench to surge beyond Jesus Vallejo in the 108th minute and drill a low shot off the boot of Simon and into the roof of the net.