A bit of melancholy and unbridled joy converged at the closing ceremony of the 2016 Olympics on Sunday as Brazil breathed a collective sigh of relief for 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 favourite sports, men's football 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 multi-coloured macaws flying over Rio's world-famous landmarks, Christ the Redeemer and Sugarloaf Mountain, before forming the five Olympic rings.
On a stormy night, wind blew through Brazil's most storied stadium and the power briefly went out in part of the stadium and the surrounding neighbourhood shortly before the ceremony kicked off.
Nostalgic notes from the traditional music of Rio's neighbourhoods and a representation of 1930s icon Carmen Miranda set the stage for the entry of hundreds of the 11,000 athletes who came to Rio and the last medal ceremony, for the men's marathon run early in the day.
The city will hand over the Olympic flag to Tokyo, site of the 2020 Summer Games, and extinguish the Olympic flame, burning since Aug. 5 in a small, environmentally friendly cauldron.
Rio will be remembered for the comeback of American swimmer Michael Phelps, who won five golds and one silver 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.
At times, it was hard to focus on the great sporting moments happening 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 unravelled when police discovered he fabricated his story to cover up his vandalising a gas station after a drunken night out with three teammates. His lie enraged Brazilians and Americans alike.
Brazilians could 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. The military and police presence was extraordinary with 85,000 troops fanned out across venues, streets and transport hubs, double the deployment in London four years ago.
"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.
For many in the football mad nation, the best Olympic moments happened in the Maracana, where Brazil defeated Germany in football on Saturday and pieced together a widely hailed opening ceremony despite a tight budget.
"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 in the midst of its deepest economic recession since the 1930s and how much they actually helped improve the city's infrastructure.
And come Monday, with the Games no longer a distraction, Brazil gets back to its dour reality of duelling 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. He said he would come for next month's Paralympic Games.
Rio Olympics Medal Tally: US tops, India 67th
PHOTOS: The gold medallists on Day 16 at Rio Olympics
Gopi, Kheta Ram clock personal bests in marathon
Russia's Yelena Isinbayeva earns IOC spot despite opposition
WFI demands CBI probe into Narsingh Yadav doping scandal