Closing Ceremony of the London 2012 Olympics
The ceremonial handover of the Olympic Games flag from London to Rio has been completed, as part of a spectacular closing ceremony.
The packed show has featured some of the biggest names of British pop from decades past, including the Spice Girls, George Michael and Elbow.
The flag was handed to the Mayor of Rio, Eduardo Paes, by Games president Jacques Rogge, at the Olympic Stadium, reports the BBC.
Games chief Seb Coe said: "When our time came - Britain, we did it right."
At the close of the ceremony, watched in the stadium by the athletes and 80,000 spectators, the 204 petals of the Olympic cauldron descended to ground level and the flame was extinguished in dramatic fashion.
As spectacular fireworks went off above the stadium, the Who performed My Generation and the venue became a sea of red, white and blue.
Earlier, as part of the ceremonial handover, the Olympic flag was lowered and it was handed from London Mayor Boris Johnson to Rogge.
After Rogge presented the flag to Paes, the Brazilian national anthem, recorded by the London Philharmonic Orchestra, was played, and the stadium was transformed into the green and yellow colours of Brazil.
The handover was followed by an eight-minute segment celebrating Rio's mix of cultures, music and dance, bringing a carnival atmosphere to the proceedings and culminating in Brazilian footballer Pele appearing on stage.
Rogge thanked the city, organisers and spectators, before declaring the Games of the 30th Olympiad closed.
Take That then appeared on stage to sing their hit Rule the World. It had been thought they would not appear after Gary Barlow's child was stillborn last week.
As the band performed, ballerina Darcey Bussell appeared to fly down into the arena on top of a flaming phoenix to join the performers from Rio and lead them in a procession.
During the show the Spice Girls sang Spice Up Your Life from the top of five brightly lit London taxis. Other stars to perform included Liam Gallagher, George Michael and Jessie J.
Big Ben chimed at 21:00 BST to start the finale, as a spectacular cityscape in the shape of a union jack was unveiled.
Silence descended as a fanfare from the Household Division Ceremonial State Band announced the arrival of Prince Harry, who is at the ceremony in place of the Queen, and Rogge, president of the International Olympic Committee.
The crowd was led in a resounding version of the national anthem, and the union jack was carried into the stadium and raised by representatives of the Army, Royal Navy and Royal Air Force.
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.
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 have been 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 thanked for their hard work.
The voice of the late Freddie Mercury echoed around the Stadium singing Queen's Bohemian Rhapsody, as part of the section of the show entitled A Symphony of British Music.
As the Stadium was plunged into dark blue light, images of David Bowie appeared on giant screens and a compilation of some of his most iconic songs were played out.
Model Kate Moss appeared wearing a shimmering Alexander McQueen creation, as billboards of some of the most iconic British models were paraded around the stadium.
The crowd were taken through a celebration of British eccentricity, with comedian Russell Brand singing Pure Imagination from Roald Dahl's Willy Wonka and the Chocolate Factory and the Beatle's I am the Walrus from the top of a psychedelic bus.
Brand was followed by DJ Fatboy Slim aka Norman Cook, who brought a party atmosphere to the proceedings.
Comedian Eric Idle 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.
Traditionally, the closing ceremony is a chance to celebrate what the athletes have achieved, with Olympics supremo Lord Coe describing it as a time to "party, party, party".
"This is the disco at the end of a wedding," artistic director Kim Gavin said of the ceremony
The competition has been the most successful Olympics for Team GB in 104 years, with a tally of 29 golds.
The Queen said Team GB's "outstanding" performance had "inspired" the country.
It was a successful final day for Team GB, with boxer Anthony Joshua securing the 29th gold with victory after a dramatic super-heavyweight bout. The 22-year old from London beat Italian Roberto Cammarelle.
Welsh fighter Fred Evans had to settle for silver in his welterweight bout against Serik Sapiyev from Kazakhstan and in the very last event of the Games, Samantha Murray came second for Britain in the women's modern pentathlon.
The Games have 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.
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, one of three golds during the Games for 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.
In other developments:
*US President Barack Obama telephoned David Cameron to offer his congratulations for a "brilliant" London Olympics, Downing Street said
*Chris Hoy said he would take a few weeks off before deciding on his future, telling the BBC that competing in the 2014 Commonwealth Games would be a "dream end" to his career
*David Cameron appointed the head of Locog, Lord Coe, as the UK's Olympics legacy ambassador
Crowds packed the live site at London's Hyde Park, to watch the sporting action on the big screens and enjoy a farewell concert headlined by Blur
Prime Minister David Cameron earlier said British athletes had inspired people up and down the country, and confirmed elite funding for Olympic sports would be maintained at £125m until 2016.
The Paralympics is set to start on August 29, with the revamped 560-acre (227-hectare) Olympic Park site - to be known as the Queen Elizabeth Olympic Park - then set to reopen in stages starting on the first anniversary of the opening of the Games, on July 27, 2013.