London 2012 Olympics close with spectacular ceremony
The London 2012 Olympics have ended with a spectacular musical closing ceremony and the official handover to the next host city, Rio de Janeiro.
The official Games flag was handed to the mayor of Rio before the flame at the Olympic Stadium was extinguished.
President of the International Olympic Committee, Jacques Rogge, who declared the Games of the 30th Olympiad closed just before midnight, said: "We will never forget the smiles, the kindness and the support of the wonderful volunteers, the much-needed heroes of these Games.
"You, the spectators and the public, provided the soundtrack for these Games. "Your enthusiastic cheers energised its competitors and brought a festive spirit to every Olympic venue."
At the close of the ceremony, watched in the stadium by the 10,000 athletes and 80,000 spectators, the flame was extinguished in dramatic fashion. Each nation will receive one of the cauldron's 204 petals.
As fireworks went off above the east London stadium, the Who performed My Generation and the venue became a sea of red, white and blue confetti.
The finale, which began with Big Ben chiming, paid tribute to UK music, fashion and culture.
Prince Harry represented the Queen at the ceremony, which took place on top of a stage in the shape of a union jack and saw a volunteer cast of 3,500.
The show saw the Spice Girls re-form to sing Spice Up Your Life from the top of five London taxis, and a surprise performance from Take That, who sang their hit Rule the World. It had been thought they would not appear because Gary Barlow was mourning the loss of his daughter who was delivered stillborn last Saturday.
Artistic Director Kim Gavin also brought together household names, including George Michael, Jessie J, Emeli Sande, Madness, the Pet Shop Boys, One Direction, Ray Davies and Liam Gallagher, as the best of British music went on show to the world.
During the ceremonial part of the show, the Olympic flag was waved aloft by London Mayor Boris Johnson and passed by Mr Rogge into the hands of the Mayor of Rio, Eduardo Paes.
The Brazilian national anthem rang out and the stadium was transformed into the green and yellow colours of Brazil's flag.
London 2012 chairman Lord Coe told the audience: "Today sees the closing of a wonderful Games in a wonderful city.
"We lit the flame and lit up the world."
The official handover also saw a celebration of Rio's mix of cultures, music and dance, bringing a carnival atmosphere to the proceedings.
Earlier, there was a riot of colour as the athletes entered the stadium, with four-time Olympic gold medallist sailor Ben Ainslie carrying the British flag and leading out Team GB.
The smiling athletes filled each section of the floor of the stadium, to the sound of Elbow playing their atmospheric hit, One Day Like This.
As is traditional during the closing ceremony, the final medals of the 2012 Olympics were handed out. On this occasion they went to the athletes in the men's marathon, which was won by Uganda's Stephen Kiprotich.
The 70,000 Games Maker volunteers were also thanked for their hard work during the 16 days of competition.
Home-grown fashion was celebrated with appearances from models Kate Moss and Naomi Campbell, both wearing the creations of the late Alexander McQueen, while British eccentricity also featured, with comedian Russell Brand singing the Beatles' I am the Walrus from the top of a psychedelic bus.
Comedian Eric Idle drew much laughter when he performed a typically quirky version of Always Look on the Bright Side of Life, and Muse rocked the stadium with the official anthem of the Games, Survival.
The Games ended with the US topping the final medal table with 46 golds, followed by China with 38 golds. GB came third with 29 golds - their best tally since 1908.
The Queen earlier said Team GB's "outstanding" performance had "inspired" the country.
The last day saw a final - and 29th gold - for Team GB, with boxer Anthony Joshua winning his super-heavyweight bout.