Substitute Malcom hustled in behind and opened home the victor following 108 minutes to hand Brazil the gold decoration.
Five years prior, Neymar scored the triumphant punishment as Brazil beat Germany to win their first gold on home soil.
Mikel Oyarzabal’s volley for Spain had precluded Matheus Cunha’s opener in the second 50% of ordinary time.
In a captivating challenge between two of football’s greatest heavyweights, Everton forward Richarlison missed a punishment and hit the crossbar.
Spain substitute Bryan Gil additionally hit the woodwork with a dazzling long reach strike a moment before additional time.
Brazil were contending in their third progressive gold award match at the Games – following on from the gold they won in Rio and a silver got in London 2012.
The 1992 bosses Spain were tipped for gold before the competition began as they had a crew weighed down with players who highlighted in this present summer’s European Championship.
Among them were Barcelona’s Pedri and Eric Garcia, Villarreal’s Pau Torres and Athletic Bilbao goalkeeper Unai Simon.
The Spaniards battled to hit excellent condition, regardless of crushing their direction into the last, and didn’t show sufficient quality to grab gold from Brazil.