The Rio Olympics wrapped up with a stunning closing ceremony as Tokyo was handed hosting duties for 2020.
Thousands of fans braved strong winds and rain to watch the carnival-inspired event in the Maracana Stadium on Sunday to conclude the 16-day sporting showpiece that featured 11,303 athletes from 206 nations and a refugee team.
International Olympic Committee chief Thomas Bach said: "These were a marvellous Olympics, in a marvellous city.
"Over the last 16 days a united Brazil inspired the world, in difficult times for all of us, with its irresistible joy for life."
The governor of Tokyo, Yuriko Koike, accepted the flag from Bach and Rio mayor Eduardo Paes, signaling the end of the 2016 games and the transition.
Team GB's flagbearer was women's hockey captain Kate Richardson-Walsh as Britain finished above China in the medal table behind the United States after a haul of 67 - their highest total on foreign soil.
Boxer Joe Joyce won Team GB's final medal - a silver - after losing to French rival Tony Yoka in the super-heavyweight final.
Sunday's party belonged to Brazil though, a final send-off 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 Brazilians recognise as the inventor of the aeroplane. Dressed in colourful feathers, dancers formed in the shape of the arches of Lapa, a popular area of Rio akin to Roman ruins, then morphed into the iconic Sugarloaf before changing again to the official 2016 symbol.
Samba legend Martinho da Vila also performed, followed by the athletes who entered the stadium under light rain, waving their flags to take a full part in the carnival parade.
It was a spectacular show from a country clouded in controversy in the Games build-up regarding its stuttering preparation, economic angst, security concerns and worries over the Zika virus.
Bach added: "These Games demonstrated that diversity is an enrichment for everyone. These Games were a celebration of diversity. They are leaving a unique legacy for many generations to come. History will talk about a Rio before and a much better Rio after these Games."
Rio 2016 organising committee president Carlos Arthur Nuzman said: "The Games in Rio is a great challenge, but a challenge with success. I am proud of my country, my city and my people. Rio has delivered history."