A blustery storm, a touch of melancholy and a sense of pride converged at the closing ceremony of the 2016 Olympics on Sunday as Brazil breathed a collective sigh of relief at having pulled off South America's first Games.
After a grueling 17 days, Rio de Janeiro cast aside early struggles with empty venues, security scares and a mysterious green diving pool to throw a huge Carnival-like party.
Samba dancers, singers, drummers and a giant plumed macaw float mixed with hundreds of athletes in the storied Maracana stadium while a final volley of fireworks lit up the night sky.
Brazilians came to the closing ceremony happy, many wearing the canary yellow jersey of the nation's sports teams, having won two late gold medals in their two favorite sports, men's soccer and volleyball.
But Sunday served up tough weather conditions for such a big party. High winds buffeted the Maracana, power briefly went out in the upper part of the stadium, and rain drenched performers and athletes as they entered the ceremony, many with medals hanging around their necks.
To the beat of traditional Brazilian music, Olympians danced and waved their countries' flags to celebrate their place on the world's premier sporting stage.
In the last of 306 medal ceremonies, International Olympic Committee President Thomas Bach draped the gold around the neck of Kenya's Eliud Kipchoge, winner of the men's marathon earlier in the day.
The city handed over the Olympic flag to Tokyo, site of the 2020 Summer Games, and Japanese Prime Minister Shinzo Abe appeared in the stadium dressed as popular video game character Mario, tunneling from Tokyo to Rio. Bach declared the Rio Games closed and expressed hope that they had left a lasting mark on the metropolitan area of 12 million people.
"These Olympic Games are leaving a unique legacy for generations to come," he said. "History will talk about a Rio de Janeiro before and a much better Rio de Janeiro after the Olympic Games."
In a final symbolic act, the Olympic flame that had burned since Aug. 5 was then extinguished in a downpour of artificial rain.