RIO DE JANEIRO (AP) — Brazil and the world bid farewell Sunday to the first Olympic Games in South America, a 16-day spectacle that combined numerous highlight reel moments with ugly and even bizarre episodes that sometimes overshadowed the competitions.

Mariene de Castro sings during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Chris Carlson)

Mariene de Castro sings during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Chris Carlson)

Thousands of fans braved strong winds and sporadic rains to watch the closing ceremony in iconic Maracana Stadium, a finale meant to be both one last bash and to take care of some business — namely signal the transition to the 2020 Summer Olympics in Japan.

Japanese Prime Minister Shinzo Abe appears as the Nintendo game character Super Mario during the closing ceremony at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. Abe’s brief but show-stopping appearance as Super Mario offered a tantalizing glimpse at Tokyo’s plans for the 2020 games. (Yu Nakajima/Kyodo News via AP)

The final party was designed to be more low-key than the opening, which focused heavily on Rio. The ceremony opened with original footage of Alberto Santos Dumont, the man that Brazilians recognize as the inventor of the airplane. Brazilians also believe he is the first to ever wear a wristwatch, an invention made by a friend so he could see the time in flight.

The theme of the show was “Brazilians can do with their bare hands,” a nod to the emerging economy of the world’s fifth largest nation.

Plumed figures appear as part of the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Mark Humphrey)

Plumed figures appear as part of the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Mark Humphrey)

Dressed in colorful feathers, dozens of dancers formed in the shape of the arches of Lapa, a popular area of Rio akin to Roman ruins, then morphed to make the shape of iconic Sugarloaf before quickly changing again, this time to the official 2016 symbol.

Samba legend Martinho da Vila, whose tunes make their way into many popular telenovelas, sang “Carinhoso,” or “Affectionate.”

Athletes from the United States pose for a photo with Simone Biles during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Matt Dunham)

Athletes from the United States pose for a photo with Simone Biles during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Matt Dunham)

Then the athletes poured in under a light rain, waving their flags while many shook their bodies to samba-infused pop that made the stadium feel like a Carnival parade.

The games had many memorable moments, both for Brazilian competitors at home and athletes from around the world.

Soccer-crazed Brazil got partial payback against Germany, winning gold two years after a 7-1 World Cup final shellacking that left many in Latin America’s largest nation fuming. American gymnast Simone Biles asserted her dominance with four golds, swimmer Michael Phelps added five more to up his staggering total to 23 and the world’s fastest man, Usain Bolt, put on his usual show with three golds just days before turning 30 years old.

Simone Biles carries the flag of the United States of America during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Matt Dunham)

Simone Biles carries the flag of the United States of America during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Matt Dunham)

But there were also ugly episodes, like American swimmer Ryan Lochte’s fabricated story about a harrowing robbery that was actually an intoxicated-fueled vandalism of a gas station bathroom, and bizarre issues like Olympic diving pools going from crystal blue to gunky, algae green — at a time when Rio’s water quality in open waters is one of the biggest local environmental issues.

Artists perform during the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Matt Dunham)

Many people, from Brazilians to International Olympic Committee members, will spend time analyzing how things went for the Rio Games in the months ahead. But on Sunday, one strong sentiment was relief — that despite some problems, overall the games went well.

Athletes surrounded by flags march into the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Charlie Riedel)

Athletes surrounded by flags march into the closing ceremony in the Maracana stadium at the 2016 Summer Olympics in Rio de Janeiro, Brazil, Sunday, Aug. 21, 2016. (AP Photo/Charlie Riedel)

That wasn’t a given going in. The Zika virus scared away some competitors and tourists, rampant street crime in Rio and recent extremist attacks around the world raised fears about safety and Brazil’s political crisis, and the economic angst behind it, threatened to cast a pall over the competitions.

___

AP Summer Games website: http://summergames.ap.org