The London Olympics were officially closed on Sunday by International Olympic Committee president Jacques Rogge, who described them as a "happy and glorious Games."
Rogge closed the Games according to IOC tradition and then invited "the youth of the world to assemble four years from now in Rio de Janeiro to celebrate the Games of the XXXI Olympiad".
The Belgian said London had witnessed 17 unforgettable days.
He thanked the organising committee, which he said was well supported by the public authorities.
"We will never forget the smiles, the kindness and the support of the wonderful volunteers, the much-needed heroes of these Games," he said as he thanked the spectators and the public.
"You have shown the world the best of British hospitality. I know that generosity of spirit will continue as we marvel at the dedication and talent of the wonderful Paralympic athletes."
Rogge said the Games would leave a legacy that will become clear in many ways
"Concrete improvements in infrastructure will benefit the host nation for years to come," he said.
"The human legacy will reach every region of the world. Many young people will be inspired to take up a sport or to pursue their dreams."
Rogge's speech came towards the end of a colourful closing ceremony attended by Prince Harry and other dignitaries.
The ceremony was like a celebration of British music, which organisers said has been one of Britain's strongest cultural exports over the last 50 years.
Several world-famous artists and groups, like George Michael, Pet Shop Boys, Queen, The Spice Girls, Take That and The Who performed on stage.
In time-honoured tradition the final victory ceremony, for marathon winner Stephen Kiprotich of Uganda was embedded in the ceremony in the Olympic Stadium amid the athletes of the world who had entered the stadium minutes earlier casually strolling in together instead of as national teams.
Many of the athletes came into the stadium proudly displaying the medals they had won.
Half a dozen volunteers then received flowers from athletes from different countries, amongst them Irish boxing Olympic champion Katie Taylor, in recognition of their unique contribution.
The flower presentation was followed by a moving segment in which a video of murdered Beatles member John Lennon singing Imagine was projected onto a giant screen.
The footage of Lennon, which has never before been seen in its entirety, was made available by his widow Yoko Ono, who was also involved in the remastering thereof.
Later on in the ceremony, there was also footage of the late Queen singer Freddie Mercury as he performed at Wembley Stadium in 1986. The 80,000 capacity crowd then joined on as the remaining band members sang their world-famous We Will Rock You with guest star Jessie J.
The official handing-over ceremony of the IOC Flag to Rio de Janeiro then followed, with the Brazilian city introduced through an artistic segment that included footballing legend Pele.
The head of the London organising committee, Lord Sebastian Coe, said they had been wonderful Games in a wonderful city.
"We lit the flame and we lit up the world.
"For the third time in its history London was granted the trust of the Olympic movement and once again we have shown ourselves worthy of that trust.
"At our opening ceremony I proclaimed that these would be a Games for everyone. At our closing ceremony I can say that these were a Games by everyone.
"This may be the end of these two glorious weeks in London. But what we have begun will not stop now. The spirit of these Olympics will inspire a generation."
After the speeches by Coe and Rogge The Who performed the final songs, including their 1970 hit See Me, Feel Me and 'My Generation.
A fireworks display then lit the sky of London as the curtain was drawn closed on the XXX Olympiad.