* U.S. basketball men down Spain in hard-fought final
* Ugandan beats Kenyan pair to win marathon
* Main stadium transformed for closing ceremony
* Spice Girls, George Michael, The Who likely to perform
* Chinese still upset by doping insinuation
By Mark Trevelyan and Matt Falloon
LONDON, Aug 12 (Reuters) - The U.S. basketball men sank Spain in one of the last finals of the London Games on Sunday, sealing their dominance of the sport and that of the entire American team which won 46 Olympic gold medals to second-placed China's 38.
At the main stadium in London's East End, the closing ceremony was due to bring the curtain down on 16 full days of spectacular sporting action, passionate crowds and the thrill of watching hosts Britain punch well above their weight.
The Spice Girls, The Who and George Michael are among the big names set to perform at a concert titled "A Symphony of British Music" which will feature more than 30 hits from the last five decades.
"This is the disco at the end of a wedding," artistic director Kim Gavin said of the ceremony, at the conclusion of which the Olympic Flame is extinguished and all eyes turn from London to 2016 hosts Rio de Janeiro.
Before the ceremony there were the last few medals to decide, and in the big match of the day the group of U.S. NBA All-Stars including LeBron James, Kevin Durant and Kobe Bryant downed Spain in a repeat of the final in Beijing in 2008.
The score of 107-100 reflected a closely-fought contest played at breakneck speed in which Durant led the scoring with 30 points.
Earlier on Sunday, Stephen Kiprotich of Uganda broke away from two Kenyan rivals to win the men's marathon near Buckingham Palace before vast crowds, reflecting local enthusiasm for the Games despite doubts about the cost and potential disruption.
After running side by side with world champion Abel Kirui and Wilson Kipsang, the 23-year-old put in a powerful kick to shake off the Kenyans six k i lometres from the end of the 42km race. He crossed the finish line draped in the red, black and yellow Ugandan flag, which he knelt to kiss.
Britain's best medal haul for a century, the record-breaking exploits of swimmer Michael Phelps and sprint pyrotechnics of Usain Bolt, who won his third London gold when Jamaica smashed the 4x100 metres world relay record on Saturday, have made for a memorable Olympics.
"I will say history has been written by many athletes. The Games were absolutely fabulous. London has absolutely refreshed the Games," International Olympic Committee President Jacques Rogge told reporters.
On the final day of competition, Britain, Cuba, Kazakhstan, Russia and Ukraine picked up golds for boxing and Japan and the United States for wrestling.
The women's modern pentathlon was the final medal to be decided, and Lithuanian Laura Asadauskaite beat Briton Sam Murray to the gold to round off London's extravaganza of sport.
Few moments could top Saturday night's spectacle on the track when Bolt anchored Jamaica to relay gold and Britain's Mo Farah claimed the 5,000m to go with his 10,000m title.
Bolt added the relay crown to the 'double double' he won in the 100 and 200, defending both after his Beijing triumphs and writing his way into Olympic history as one of the finest - and zaniest - sprinters the world has known.
As he crossed the line, Bolt made his hands into an 'M' shape above his head - a nod to Farah's famous celebration, while the Briton later copied Bolt's well-known lightning strike pose as two of the stand-out performers of the Games had fun.
Bolt went straight on to a London nightclub to delight dancing fans with a turn as a DJ, shouting out "I am a legend" to the packed dancefloor.
Farah, contributing to Britain's 29 golds, is the seventh man to win the 5,000 and 10,000 titles at the same Olympics.
British Prime Minister David Cameron hailed the Games in a succinct message on Twitter: "Britain delivered. We showed the world what we're made of."
Despite concerns about the creaky transport system and a shortfall of private security guards, which forced the government to call in thousands of extra troops to help screen visitors, the Games have so far passed by fairly trouble-free.
A furore over empty seats at several Olympic venues blew over, especially once the track and field showcase kicked in and drew capacity crowds of 80,000 for virtually every session.
Even the weather improved as the Games wore on. Bright sunshine has graced the closing weekend of a festival that has helped to lift the gloom in recession-hit Britain.
For some, though, London left a bitter taste.
China bowed out of the Games with a swipe at the critics who had accused teenage swimming sensation Ye Shiwen of doping after her times rivalled the top U.S. men.
Aged just 16, Ye set a world record, a Games record and won two gold medals in the women's individual medleys, but her victories were overshadowed by questions and insinuations of cheating. There was no evidence that she had broken any rules.
The head of the Chinese delegation to London, Liu Peng, said the accusations were totally unfounded and stressed that China was strongly opposed to any doping "misbehaviour".
"This is really unfair. This is groundless," Liu told a news conference on Sunday. "There are individuals and media that are accusing, unfounded, our Chinese athletes. These people should respect sporting persons' dignity and their reputation."