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.
It was far from a perfect execution by Brazil, which battled with empty seats, security scares and a mysterious green diving pool. But two late gold medals for the host country in its two favorite sports, men's soccer and volleyball, helped smooth some of the rough edges around the Games for Brazilians.
From the Maracana where it all began 16 days ago, the final event kicked off with figures dressed as multicolored macaws flying over Rio's world-famous landmarks, Christ the Redeemer and Sugarloaf Mountain, before forming the five Olympic rings.
A storm that menaced Rio all day sent wind and rain through Brazil's most storied stadium and the power briefly went out in part of the stadium and the surrounding neighborhood shortly before the ceremony kicked off.
Rain drenched performers and hundreds of athletes as they entered the party, many with medals hanging around their necks, like the U.S. men's basketball team which won gold on Sunday.
Participants celebrate during the closing ceremony.
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."
Tapping natural talent
In the midst of it worst economic recession since the 1930s, Brazil's opening and closing ceremonies relied more on the country's unique talents and natural beauty and less on expensive technology.
On Sunday, there was an ode to the white-clad lacemaking ladies and the forro music of the Northeast that sparked waves of pride among Brazilians.
Athletes take part in the closing ceremony.
One of the more stunning moments of the ceremony focused on the ancient art found in the Serra da Capivara National Park - a UNESCO World Heritage site in northeastern Brazil featuring cave paintings, some more than 25,000 years old.
But the beauty was betrayed by Brazil's tough times.
Just this week, the foundation that maintains the park said it could no longer do so because of a lack of funding.
For all the troubles before and during the Games, Rio will surely be remembered for great sporting moments.
There was the remarkable comeback of American swimmer Michael Phelps, who won five golds to reinforce his distinction as the most decorated Olympian of all time.
Jamaica's Usain Bolt drew down the curtain on his brilliant Olympic career by securing a sweep of the sprint titles for a third successive Games. And American gymnast Simone Biles, the U.S. flag bearer in the closing ceremony, kicked off her Olympic run by tying the record of four gold medals in a single Games.
But at times it was hard to focus on the sporting triumphs taking place across the sprawling city.
A low point for Rio came when Ryan Lochte, one of America's most decorated swimmers, said he was robbed at gunpoint. That ignited further security concerns after a series of assaults against government ministers, athletes and tourists.
But Lochte's story quickly unraveled, enraging Brazilians and Americans alike.
Brazilians could nevertheless take heart in the fact that there were no major mishaps or breaches after deadly attacks in Europe and the United States had prompted the biggest security operation in Brazil's history with 85,000 troops.
"Even with all our problems we pulled off a good Olympics. Nothing too bad happened and I'd say it was better than expected," said Nivea Araujo, a Rio resident attending the closing ceremony.
Japanese Prime Minister Shinzo Abe takes part in the closing ceremony.
For many in the soccer-mad nation, the best Olympic moments happened in the Maracana, where Brazil defeated Germany in soccer on Saturday and pieced together a widely hailed opening ceremony despite the tight budget.
Rio won the right to host the Games in 2009, when the economy was booming and millions were pushing into the middle class.
"We are in a difficult moment as a country right now, we can't hide that, but the Games were scheduled and I'm glad we could enjoy them," said Alessandro Freitas, also from Rio.
One of the major concerns for Brazilians is what will be the final cost of the Games for a country and how much they actually helped improve the city's infrastructure. Many Rio residents could not afford tickets to events, leaving them feeling on the sidelines of the city's biggest undertaking.
And come Monday, with the Games no longer a distraction, Brazil gets back to its dour reality of dueling political and economic crises. An impeachment vote in coming days could lead to the permanent ouster of suspended President Dilma Rousseff.
Interim President Michel Temer, who was booed at the opening ceremony, decided not to attend the closing event.