Tearful Neymar scores the winning penalty to break Brazil's hoodoo and partly end the pain of 2014. An excellent encounter had finished 1-1 after extra time with unlucky Germany often finding the crossbar.
Hosts Brazil beat Germany 5-4 on penalties to win the Olympic men's soccer gold medal for the first time after a highly engaging 1-1 draw in a feverish Maracana.
Brazil star Neymar netted the decisive spotkick and broke into tears after Germany substitute Nils Petersen had been the only man to miss following a quality encounter, which proved once and for all that Olympic football really does matter.
Olympic gold was the only major honor Brazil's men had previously failed to capture.
Neymar, handed another chance of home glory after the disappointment of the 2014 World Cup, gave the hosts the lead in the 26th minute when his powerful dipping freekick went in off the underside of the bar.
Germany captain Max Meyer also netted his fourth of the tournament when he hit back just before the hour mark, sweeping home following a fine move.
Much was made before kickoff of the last time Germany faced Brazil, when the would-be world champions thumped the World Cup hosts 7-1 in the 2014 semi-final.
But in truth, not a single player on the field in the Olympic final had been in that semi, with Neymar having been injured and Germany´s Matthias Ginter an unused substitute two years ago.
Talk of revenge was cheap although there was perhaps extra pressure on the German men after the women's team took gold on the same iconic Maracana pitch on Friday.
In any case, the Germans started the game better at the packed Rio stadium and struck the woodwork three times in the first half amid an electric atmosphere.
Julian Brandt hit the bar from distance with a curling effort after 10 minutes. Meyer's freekick was then deflected onto the woodwork while Sven Bender's near-post flicks also struck the crossbar.
Brazil had other opportunities too with Luan's shot being blocked while in the second half Gabriel Jesus prodded wide.
Neymar, one of the three overage players in the Brazil squad and the biggest name in the under-23 Olympic tournament, later drifted a decent effort just past the post as the hosts pushed harder for a winner in normal time.
In extra time Brazil were again in the ascendancy with the silky skills of Luan almost creating an early opening although Brandt also went close for Germany with a spectacular volley. Felipe Anderson should have done better when put through as time ticked down to penalties with Neymar also firing over.
In the end the lottery of penalties decided the clash and it was written in the stars that Neymar would be the man to seal victory for the Brazilians and spark an all-night Rio party.
The Games have been somewhat underwhelming for the hosts but Olympic gold in men's football gives the masses the result they desired the most.
With the Rio extravaganza slowly drawing to a close, many neutrals would say it is the perfect way to end an otherwise controversial Olympics.