A blustery storm, a touch of melancholy and a sense of pride converged at the closing ceremony of the 2016 Rio Olympics as Brazil breathed a collective sigh of relief at having pulled off South America's first Games.
After a gruelling 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 on Sunday.
But as the Games came to an end, concerns regarding the country's political and economic condition will begin to re-surface.
But at the Maracana, samba dancers, singers, drummers and a giant plumed macaw float mixed with hundreds of athletes in the storeyed 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 favourite sports, men's football 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.
|A spectacular ceremony inside the Maracana, but problems still exist for Brazil outside the stadium [AFP]
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, tunnelling from Tokyo to Rio.
International Olympics Committee President Thomas Bach declared the Rio Games closed and expressed hope that they had left a lasting mark on the metropolitan area of 12 million people.
In the midst of its 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.
Rio 2016: Usain Bolt, from strong child to track king
Al Jazeera's Latin America editor Lucia Newman, reporting from Rio, said the Games passed by largely without incident despite all the concerns about possible terrorist attacks and other security issues.
"Thousands gathered at the Olympic Boulevard for a last chance to take a photo in front of the flame before it went out," she said.
"Despite all the problems Brazil was facing, the country's Olympic team has never done better than its performance in Rio, giving the nation a very welcome reason to celebrate."
On the field, 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 US 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 prompted further security concerns after a series of assaults against government ministers, athletes and tourists.
OPINION: The politics behind the Olympic spirit
But Lochte's story quickly unravelled, 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 US had prompted the biggest security operation in Brazil's history with 85,000 troops.
"You know, before coming here there was so much talk of precautions, Zika this and that, but honestly, everything has been amazing," Cesar Harris, a US resident, told Al Jazeera in Rio.
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 ousting of suspended President Dilma Rousseff.
Source: Al Jazeera and agencies