(CNN) - Legendary track star and chairman of the London Organizing Committee Sebastian Coe congratulated his fellow Britons for a "glorious" Olympic Games on Sunday night.
"When our time came, Britain, we did it right," Coe told the 80,000 gathered at Olympic Stadium for the closing ceremony.
Coe said these "two glorious weeks" would "inspire a generation."
International Olympic Committee President Jacques Rogge declared the London Games officially over.
He echoed Coe's sentiments.
"These were happy and glorious Games," he said. "The legacy of the Games of the 30th Olympiad will become clear in many ways. Concrete improvements in infrastructure will benefit the host nation for years to come. 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."
As the Games came to a close, the United States led the medal count with 104 overall, 46 of them gold.
China finished second, with 87 medals, with Russia third with 82. Great Britain finished with 65, its best total since 1908.
Singers from all eras performed. There was rock great Ray Davies, pop heroes George Michael and Annie Lennox, and new boy-band One Direction. Even comedian Russell Brand joined in, singing The Beatles "I Am The Walrus."
The crowd gave the Spice Girls a rousing ovation after they performed two of their hits.
Other performers payed tribute to some of the artists who didn't attend or had passed away.
Singers Jessie J and Taio Cruz teamed with rapper Tinie Tempah to sing "You Should Be Dancing" by the Bee Gees (born on Isle of Man). Ed Sheeran led a quartet with Pink Floyd drummer Nick Mason, Richard Jones of the Feeling and Mike Rutherford of Genesis in covering "Wish You Were Here."
Later Monty Python actor Eric Idle led the crowd in singing "Always Look on the Bright Side of Life."
To close the music medley Jessie J also joined Brian May and Roger Taylor of Queen, belting out "We Will Rock You."
The Who closed out the ceremony with a medley of the band's hits, ending with "My Generation."
In a new twist, the 10,000-plus athletes entered the stadium through the stands, some high-fiving members of the audience as they descended the steps to the field.
There was also one final medal ceremony as Stephen Kiprotich of Uganda was awarded his marathon gold and listened along with the spectators to his national anthem.
The White House released a statement that said President Obama called British Prime Minister David Cameron congratulating London on an "extremely successful" games.
One of the U.S. golds came as expected on the basketball court, but in a tougher contest than expected.
Led by Kevin Durant's 30 points, the United States fought off a stiff challenge from Spain to win the gold medal 107-100.
The Americans defended their title from four years ago in Beijing, also against Spain.
"This game was fun. It was a challenge, but we stepped up to it," Kobe Bryant told NBC, an official broadcaster of the Games.
LeBron James had 19 points and Bryant scored 17 for the Americans, who led by only one point after the third quarter.
"We all respect each other," Durant said. "We all know it's our common goal."
Russia narrowly edged out Argentina for the bronze.
London itself took center stage on the last day of the Olympics on Sunday, with the men's marathon course running past the city's major landmarks from Big Ben to Buckingham Palace.
Kiprotich won a thrilling race in 2:08:01, dueling for miles with early leader Wilson Kipsang of Kenya and his compatriot Abel Kirui.
The Kenyans worked together to try to box the Ugandan in, but as the race neared its end, he blew past them to finish with a commanding lead, giving Uganda its first medal of any color in these Games.
Read more: Nigeria's 12- year wait for Olympic gold
Kirui took silver and Wilson Kipsang Kiprotich took the bronze, with Eritrea-born American Meb Keflezighi coming fourth, about three minutes behind the winner.
The hosts snatched yet another boxing gold medal later Sunday, with super heavyweight Anthony Joshua winning gold for Britain. Italy, whose Roberto Cammarelle won silver, launched an appeal after the fight ended 18-18. Joshua was awarded victory on countback -- using the scores of all five judges, not just the middle three scores.
"It was a tough first round. The judges will always do their job and I do my job," the champion said. "I have had close decisions in other tournaments but I just take it on the chin."
The Italian said the decision was curious.
"I did everything I could. I don't understand the score," he said. "Where did they get all the points they gave him at the end?"
Team USA picked up another gold medal earlier, when Jacob Stephen Varner won the 96-kilogram
freestyle wrestling contest.
"I came here to win a gold medal and that's what I've done," he said. "I played more defense then I wanted to, but it's awesome for the United States."
Uzbekistan's Artur Taymazov became first man to win three consecutive freestyle wrestling golds, defeating Davit Modzmanashvili of Georgia.
"I wanted to get the third gold," said Taymazov, who also won a silver at the Sydney Games in 2000. "There was also a time pressure, because I am 33. But it was my time."
At the 2000 Olympics, Greco-Roman wrestler Alexander Karelin won three straight golds and then a silver.
"I'm glad I have equaled his medal total," Taymazov said, "but he has won more world championships than I have won so I must do more over the next two seasons."
In men's water polo, Ratko Rudic guided Croatia to an 8-6 victory over Italy in the gold medal match, a record fourth win for the a coach. Rudic has led three nations -- Yugoslavia, Italy and his native Croatia -- to gold as well as winning a silver medal in 1980 as a player with Yugoslavia.
Laura Asadauskaite of Lithuania won the final gold medal of the London Games with an Olympic record score in the modern pentathlon.