The colourful ceremony, lasting almost three hours, celebrated Brazil’s arts and was held in a wet Maracana.
Among the highlights were Tokyo’s impressive showcase and a vibrant carnival parade.
“These were a marvellous Olympics, in a marvellous city,” said International Olympic Committee chief Thomas Bach.
“Over the last 16 days a united Brazil inspired the world, in difficult times for all of us, with its irresistible joy for life.”
Bach officially closed the Games of the 31st Olympiad after 16 days of competition, featuring 11,303 athletes from 206 nations and a refugee team.
One of the biggest cheers of the night was for Japanese prime minister Shinzo Abe, who turned into the video game plumber Super Mario and then popped out of a huge green pipe in the stadium.
The ceremony, watched by billions around the world, featured the parade of athletes and a dramatic extinguishing of the Olympic flame.
Women’s hockey captain Kate Richardson-Walsh carried the flag for Great Britain, who finished the Games with 67 medals – their highest tally at an overseas Olympics.
Gold Silver Bronze Total
Full medal table
US 46 37 38 121
Great Britain 27 23 17 67
China 26 18 26 70
Athletes parade at the Maracana Stadium during the closing ceremony of the 2016 Rio Olympic Games in Rio de Janeiro, Brazil, Aug. 21, 2016.