Braving the wind and heavy rain of Brazil's tropical winter, 50,000 spectators witnessed a showcase of Brazilian music and culture in Rio's iconic Maracana Stadium before the Olympic athletes entered the scene.
US gymnastics star Simone Biles carried her country's flag – Biles won four gold and one bronze medal at the Games, helping push her country to the top of the medal table.
The 207 national delegations also included a team of refugees for the first time in Olympic history - an initiative by the United Nations and the International Olympic Committee (IOC) to highlight the plight of the 65 million displaced people around the world.
Canoer Isaquias Queiroz dos Santos, winner of two silver and one bronze medal, lead the Brazilian team.
Having survived a kidnapping, severe burns and a serious accident as a child, Queiroz dos Santos was one of the many athletes competing in Rio who had overcome great hardships on the road to the Olympic stage.
Following Olympic tradition, the Game's final medals were awarded during the closing ceremony, to Kenyan veteran runner Eliud Kipchoge who won the men's marathon on Sunday, and to Ethiopian Feyisa Lilesa and US athlete Galen Rupp who finished second and third.
While the Brazilian show highlighted the country's ancient indigenous cultures and its colonial history through riveting song and dance, 2020 host city Tokyo staged a surprisingly funny high-tech show that ended with a bang.
To the powerful music of Japanese pop star Sheena Ringo, Japanese Premier Shinzo Abe appeared in a video in which he transformed into the video game character Super Mario while driving through Tokyo.
Super Mario was then seen drilling through the centre of the earth to Rio, before Abe appearing in person in the centre of the stadium, tearing off his Super Mario mask to roaring applause.
In a symbolic gesture, Rio's mayor Eduardo Paes handed the Olympic flag to Tokyo governor Yuriko Koike, who will need to prepare for the world's biggest sporting event in the coming years.
IOC president Thomas Bach formally closed the Games, declaring them "marvellous Olympic Games in THE marvellous city!"
"Over the past sixteen days a united Brazil hosted the world in these difficult times for us all, through its irresistible joy," he said.
The first Games in South America faced many challenges, ranging from empty seats at the venues to security concerns, all while the host nation was going through its worst economic crisis since the 1930s.
Brazil is also undergoing a political crisis, with unpopular acting President Michel Temer not attending the Games' close after being booed at the opening ceremony.
"History will talk about a Rio de Janeiro before and a much better Rio de Janeiro after the Olympic Games," Bach said, referring to the infrastructure projects that were built for the giant sports event.
However, power blackouts in the favelas surrounding the Maracana Stadium during the closing ceremony highlighted the lingering problems that Rio's poor will continue to face.
But in true Rio style, samba schools from poor areas of the city flooded the stadium for a glittering carnival parade at the event's finale, celebrating life rather than dwelling on its problems.
- DPA