Scandal and controversy may have dogged the Olympic Games, but Rio de Janeiro signed off in style with a tropical closing ceremony.
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 favourite sports, men's soccer and volleyball, helped smooth some of the rough edges of the Games for Brazilians.
From the Maracana where it all began 16 days ago, the final event kicked off with figures dressed as multi-colored 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.
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. The first Refugee team in Olympic history, one of the biggest crowd-pleasers of the Games, marched in behind the Olympic flag, carried by a Congolese judoka and Rio resident.
The athletes witnessed the last of 306 medal ceremonies, for the men's marathon earlier in the day. The city will then 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.
Sport competes with scandal
These games certainly had their magic moments. Usain Bolt delivered not once, but three times – for the third time - to underline his status as the greatest sprinter of all time.
Mo Farah completed the double double to add the 5000m to his 10000m title with a spine-tingling sprint to the line, reminiscent of four years ago in London.
And then there was the maiden Olympic victory for Brazil's footballers, which was probably the most important gold medal for the home nation, in the only sport Brazil really cares about. Their golden boy, Neymar, guided his nation to victory against a strong German side, with the horror of that 7-1 defeat at the last World Cup lurking in the background.
It's telling that the one sport whose very presence at the Olympics is often met with cynicism, is the only one that truly ignited the imagination of a very skeptical Brazilian public.
And of course there's the American duo of Michael Phelps and Simone Biles. Both won four golds of a possible five at these Games, and both confirming themselves as the pinnacle athletes in swimming and gymnastics, respectively. Phelps, of course, can now claim to be the greatest Olympian in history.
But 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 vandalizing 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.
"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.