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."