The Rio Olympics have ended in a blaze of color with a carnival-inspired closing ceremony at the Maracana stadium.
Some 50,000 spectators braved the wind and pouring rain of Brazil's tropical winter to see the August 21 event, which featured the parade of athletes and the symbolic handover of the Olympic flag to 2020 hosts Tokyo.
International Olympic Committee (IOC) President Thomas Bach officially closed South America's first Olympiad after 16 days of competition featuring more than 11,300 athletes from 206 nations and a refugee team.
"These were a marvelous Olympics in a marvelous city," Bach said before the flame in the Olympic cauldron was extinguished. "Over the last 16 days, a united Brazil inspired the world, in difficult times for all of us, with its irresistible joy for life."
Tokyo Governor Yuriko Koike received the flag from the IOC president, signaling the transition to the 2020 Olympics.
A showcase of the Japanese capital included Prime Minister Shinzo Abe, dressed as computer game character Super Mario, popping out of a green pipe that he allegedly used as a shortcut to get from Tokyo to Rio.
The Rio Olympics had many memorable moments, including the comeback of 31-year-old American swimmer Michael Phelps, who won five gold medals and one silver to reinforce his distinction as the most decorated Olympian of all time.
The world's fastest man, Jamaica's 30-year-old Usain Bolt, secured a sweep of the sprint titles with three more golds.
South Africa's Wayde van Niekerk, 24, delivered one of Rio’s greatest performances as he broke Michael Johnson's 17-year-old 400-meter record.
American gymnast Simone Biles, 19, kicked off her Olympic run by tying the record of four gold medals in a single Olympiad.
Majlinda Kelmendi made Olympic history for Kosovo, winning a gold medal in women's judo and becoming the first athlete from the Balkan nation to win an Olympic medal.
Dilshod Nazarov of Tajikistan won the men's hammer event, handing the Central Asian nation its first-ever Olympic gold medal.
And Kimia Alizadeh returned to Iran with a bronze medal in taekwondo -- the first Olympic medal won by an Iranian woman.
But for many in soccer-crazed Brazil, the best moment happened when Neymar scored the winning penalty in the shootout as Brazil beat Germany to win their first men's Olympic football gold medal.
A low point came when Egyptian Islam El Shehaby refused to shake the hand of Israeli opponent Os Sasson after losing in men's judo.
But perhaps the biggest embarrassment was felt by U.S. swimmer Ryan Lochte, who claimed he was robbed at gunpoint. Police later discovered Lochte fabricated the story after he and his teammates vandalized a gas station bathroom following a drunken night.
The Olympics were not affected by any major incidents, but safety concerns, a diving pool turning green, and the Russian doping controversy frequently overshadowed the sports action.
The biggest loser of the Rio Olympics is probably Russia, which finished fourth in the medals table behind the United States, Britain, and China.
The Russian athletes are bringing home a total of 56 medals -- 19 golds, 18 silvers, and 19 bronze -- a far cry from the 82 medals they picked up at the 2012 Olympics in London.
The Russian Olympic team was decimated with nearly 120 athletes barred from competing in the wake of a report by the World Anti-Doping Agency describing systematic doping in Russia involving the main state security agency and the country’s main anti-doping laboratory.
"With all my heart, I congratulate all our outstanding athletes, winners, prizewinners, our entire team," the head of the State Duma's sports committee, Dmitry Svishchev, was quoted by the TASS news agency as saying.
"They were acting in difficult conditions, under serious pressing,” Svishchev added. “I think these were one of the tensest games for the history of both Russia and the Soviet Union. This is a huge victory,"
On the final day of the Rio Olympics, Uzbekistan scored two gold medals in boxing.
Shakhobidin Zoirov notched an upset victory over two-time Russian world champion Mikhail Aloyan to capture the gold medal in the flyweight division.
And Fazliddin Gaibnazarov defeated Cuban-born Lorenzo Sotomayor Collazo, who was fighting under Azerbaijan’s flag, in the light welterweight final. Russia's Vitaly Dunaytsev took a bronze medal.
Russia won its fifth straight Olympic gold medal in the group all-around event in rhythmic gymnastics. The five-woman team maintained its grip on the title a day after Margarita Mamun achieved the same feat by winning a fifth-straight individual all-around crown for Russia.
Russia's Soslan Ramonov defeated Azerbaijan's Toghrul Asgarov to win the men's freestyle wrestling gold medal in the 65-kilogram weight class.
Azerbaijan's Khetag Gazyumov took home the silver medal in the men's 97-kilogram freestyle wrestling, while Uzbekistan's Magomed Ibragimov won a bronze medal.
The U.S. men's basketball team beat Serbia 96-66 for the gold medal.
Kazakhstan's Ivan Dychko was awarded a bronze medal in the men's super-heavyweight boxing.
There were furious scenes when two Mongolian coaches stripped off their clothes in protest after their wrestler -- Mandakhnaran Ganzorig -- lost a bronze-medal match against his Uzbek opponent, Ikhtiyor Navruzov.