Farah defended his 5,000-meter Olympic crown in the Estádio Olímpico Joao Havelange to add to his earlier successful defense of the 10,000m title he first won at London 2012.
Paul Kipkemoi Chelimo of the US originally finished second but was subsequently disqualified, pushing compatriot Bernard Lagat into the bronze medal position and Ethiopia's Hagos Gebrhiwet up to silver.
Farah's triumph means he becomes just the second man after Finland's Lasse Viren to win both the long-distance events at successive Olympics.
"It's every athlete's dream, but I can't believe it," Farah told reporters.
"I just want to go home now and see my beautiful kids and hang my medals around their necks."
The 33-year-old's triumph heralded wider success for Great Britain, which has now passed the 65 medals it achieved in London four years ago.
The 66th came shortly after Farah's win, as Christine Ohuruogu crossed the line to claim bronze for Britain in the women's 4x400m final.
Gold went to the US lineup of Courtney Okolo, Natasha Hastings, Phyllis Francis and Allyson Felix -- the country's sixth in a row in the event.
The last time the US failed to win the title was in Barcelona 1992. Meanwhile, Felix now has six Olympic gold medals to her name, more than any other female track athlete has achieved.
Another piece of US athletic history was made when Matt Centrowitz grabbed gold in the men's 1,500m final, the first time an American man has won that event since 1908.
It was down to the men of Team USA to close out the track and field events of Rio 2016 by surging home ahead of Jamaica in their 4x400m final, with defending champion the Bahamas in third.
Their success was the 13th gold, and 31st medal, in track and field events for the US in Rio.
Semenya claims 800m gold
In the women's 800m final, Caster Semenya of South Africa burst clear to take gold ahead of Francine Niyonsaba of Burundi in second and Kenya's Margaret Wambui in third.
Semenya, the London 2012 silver medalist, has had to suffer aspersions around her gender in recent years.
The 25-year-old has hyperandrogenism
-- meaning elevated testosterone levels -- and there has been public and often bitter controversy about whether she should be competing in female athletic events.
While athletics' governing body the IAAF ruled in 2011 that female athletes whose testosterone levels were above a set level would have to use medication to bring those levels down, that decision was overturned last year by the Court of Arbitration for Sport.
A tearful Lynsey Sharp of the UK, who finished sixth, appeared to decry the difficulty of competing with Semenya when interviewed by BBC Sport after the race.
But Semenya chose to focus on her own considerable struggles, travails and sacrifices in becoming Olympic champion when speaking to reporters.
"The field was really good. It was fantastic to race with such great athletes," Semenya said after setting a national record time of one minute 55.28 seconds.
"I dedicate this to my team. They've done a fantastic job."
A YouTube silver
In the men's javelin final, Youtube-coached world champion Julius Yego of Kenya
could only claim silver behind Thomas Rohler of Germany.
Rohler landed a distance of 90.30 meters, considerably more than Yego's 88.24 and the 85.38 made by third-placed defending champion Keshorn Walcott of Trinidad and Tobago.
In the women's high jump final, Spain's Ruth Beitia won gold with a leap of 1.97m ahead of Bulgaria's Mirela Demireva in second and Blanka Vlasic of Croatia in third.