The victory gave Brazil a measure of revenge for their humiliating 7-1 defeat by eventual World Cup 2014 winners Germany in the semi-finals on home soil.
Neymar shed tears of joy after delivering Brazil's first men's soccer gold medal with the winning penalty in a 5-4 shootout triumph over Germany after a thrilling final ended in a draw following extra-time on Saturday.
Shortly after the win, Neymar said he will step down as Brazil's captain after leading the Olympic Games' hosts to their first ever football gold medal.
Brazil had lost the Olympic final three times - in 1984, 1988 and 2012 - but finally got the gold they craved on a dramatic night at the Maracana stadium in which they outplayed the Germans but were saved three times by the woodwork.
Neymar had put the hosts ahead with a superb free kick after 27 minutes but German Captain Maximilian Meyer equalized just before the hour to take the game into the extra period at 1-1.
There were no more goals so the match went to penalties with Nils Petersen missing Germany's fifth spot kick leaving Neymar, who appeared to injure himself late in the game, to limp up and coolly score from the spot to send the capacity crowd wild.
The victory gave Brazil a measure of revenge for their humiliating 7-1 defeat by eventual World Cup 2014 winners Germany in the semi-finals on home soil, a game the frustrated Neymar had to watch from the sidelines due to injury.
"Yesterday we were criticized," the 24-year-old Barcelona forward said in reference to Brazil's poor start to the Olympic tournament in which the home side drew 0-0 with South Africa and Iraq. "We have replied with good football."
Brazil coach Rogerio Micale added, "We had players who were extremely dedicated, professional and with great technical skill. I'll leave here with the sensation of having done my duty."
The win means a unified Germany are now the only World Cup winners never to have won the Olympic gold medal and the loss robbed them of a chance to complete the male and female double after their women's team beat Sweden 2-1 on Friday.
With a passionate crowd behind them, Brazil took the game to their opponents and dominated possession and territory.
However, they struggled to make chances and it was the Germans who almost opened the scoring after 10 minutes when Julian Brandt smacked the bar with a lovely curling shot from outside the box.
Brazil kept pushing forward and just before the half-hour mark they got the goal that their play deserved.
Neymar was brought down almost 25 meters from goal and, although the angle was tight, he curled a spectacular strike into the net off the underside of Timo Horn's bar.
The goal shook Germany into action and they pushed forward more and hit the bar twice more before the half was out.
Brazil still looked the hungrier side but it was Germany who got the next goal with an hour gone. Jeremy Toljan sent in a low cross from the right and captain Maximilian Meyer swept home a lovely finish from about 10 meters.
Gabriel Jesus almost put Brazil ahead when he touched a Renato Augusto cross wide after 64 minutes and Felipe Anderson should have given the hosts the lead 13 minutes later but he was caught in possession with only the keeper to beat.
Anderson then almost scored 16 minutes into extra time but Horn got down superbly to block his shot as he raced in on goal.
With the sides still level after extra time, the stage was set for Neymar to step up and strike the winning spot kick to send the whole of Brazil into raptures as the country finally captured the Olympic title they had so desperately craved.
Jubilation on the streets
For Brazilian fans it felt as if the country won the entire Olympics as fans danced in the streets. Drivers of cars and trucks hooted and crowds in countless venues across the city screamed in a Saturday night delight.
"The champions are back, the champions are back!" they chanted.
"Brazil could have won (gold) medals in everything but if it hadn't been in football then nothing would have counted," said Leila Lopes da Silva, 70, who joined the dancing and chanting at a viewing venue close to the beach.
"Volleyball, judo, that's all fine," she said. "But football was what we needed."