Fireworks explode during the opening ceremony.— Reuters
The joyful opening contrasted with months of turmoil and chaos, not only in the organisation of the Olympics but across Brazil as it endures its worst economic recession in decades and a deep political crisis.
Temer, flanked by dozens of heads of state, played a minor role in the ceremony, speaking just a few words.
The leader who was supposed to preside over the Games, President Dilma Rousseff, was suspended last May to face an impeachment trial and tweeted that she was “sad to not be at the party”.
The $12 billion price tag to organise the Games has aggrieved many in the nation of 200 million and in Rio, where few can see the benefits of the spectacle or even afford to attend the Games.
Due to Brazil's most intense security operation ever, some among the 50,000 attendees faced two-hour-long lines to enter the venue.
People on the periphery
The creative minds behind the opening ceremony were determined to put on a show that would not offend a country in dire economic straits but would showcase the famously upbeat nature of Brazilians.
It started with the beginning of life itself in Brazil, and the population that formed in the vast forests and built their communal huts, the ocas.
The Portuguese bobbed to shore in boats, the African slaves rolled in on wheels and together they ploughed through the forests and planted the seeds of modern Brazil.
“They're talking about slavery? Wow,” said Bryan Hossy, a black Brazilian who watched the ceremony in a bar in Copacabana. “They have to talk about that. It's our story.”
The mega-cities of Brazil formed in a dizzying video display as acrobats jumped from roof to roof of emerging buildings and then on to the steep favela that served as the front stage for the ceremony.
From the favela came Brazilian funk, a contemporary mash-up of 20th century rhythms, sung by stars Karol Conka and 12-year-old rapper MC Soffia.
“This is a conquest. The people on the periphery are having an influence, it's a recognition of their art,” said Eduardo Alves, director of social watchdog Observatorio de Favelas.
Before the entry of a few thousand of the 11,000 athletes that will be competing in the Games, the playful rhythms of the ceremony gave way to a sober message about climate change and rampant deforestation of the Amazon.
Each athlete will be asked to plant seeds that will eventually grow into trees and be planted in Rio in a few years.
The party wrapped up with a rousing parade of the city's samba schools that compete in Carnival.
Hundreds of drummers donned their colours and played out Brazil's trademark beat, as athletes from over 200 countries tried out their first steps of samba.