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 three-hour show featured some of the biggest names of British pop from decades past, including the Spice Girls, George Michael and Elbow.
Games chief Lord Coe said: "When our time came - Britain, we did it right."
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."
Best of British
At the close of the ceremony, watched by 10,000 athletes and 80,000 spectators in the stadium along with 26 million TV viewers, the flame was extinguished in dramatic fashion.
Each nation will receive one of the cauldron's 204 petals.
In other developments:
- Nadzeya Ostapchuck, of Belarus, has been stripped of the gold medal in women's shot put after failing a drugs test. New Zealand's Valerie Adams has been promoted to first place
- London airports expect to handle the departure of about 200,000 people a day this week as visitors leave following the Games. Some 120,000 are expected to leave Heathrow each day, with a further 70,000 set to fly from Gatwick
- Private security firm G4S has donated £2.5m to the armed forces after troops had to stand in for its absent staff during the Olympics
- Commentators from around the world have begun to reflect on the success of the Games, as have British observers.
On Sunday, at the closing ceremony, fireworks went off above the east London stadium, the Who performed My Generation and the venue was transformed into 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.
'Lit up the world'
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.
In all, 44 world records have been set during London 2012, and 117 Olympic records broken.
Among those to have set new world bests included Kenyan David Rudisha in the men's 800m and the Jamaican sprint relay team, which included 100m and 200m gold medallist Usain Bolt.
US swimmer Michael Phelps became the most decorated Olympian in history while cyclist Sir Chris Hoy's two gold medals meant he became the most successful British Olympian of all time.
Earlier, US President Barack Obama telephoned Prime Minister David Cameron to offer his congratulations for a "brilliant" London Olympics, Downing Street said.
On Sunday, crowds also packed London's Hyde Park to watch the sporting action on big screens and enjoy a farewell concert headlined by Blur.
The Paralympics is set to start on 29 August, with the revamped 560-acre (227-hectare) Olympic Park site - to be known as the Queen Elizabeth Olympic Park - then set to reopen from the first anniversary of the opening of the Games, on 27 July 2013.