Michael Phelps savored one last golden moment Saturday, capping his remarkable Olympic swimming career with an 18th gold medal in the final event in the Aquatics Centre competition pool.

"It's tough to put into words right now," Phelps said. "I did everything I wanted to do.

"I finished my career the way I wanted to, and I don't care what anyone says, if I can say that, it's all that matters."

With the US men unbeaten in the 4x100m medley relay in Olympic competition, the race was a coronation for the man Serbian swimmer Milorad Cavic called "the king".

But breaststroke star Kosuke Kitajima added some drama to the occasion, seizing a narrow lead for Japan by the time Phelps dived in for the butterfly leg behind US backstroker Matt Grevers and breaststroke swimmer Brendan Hansen.

Takeshi Matsuda maintained Japan's advantage at the 50m mark of the fly, but Phelps delivered a classic final lap to seize the lead for the Americans and 100m free gold medallist Nathan Adrian was untouchable in sealing the victory in 3:29.35.

"It is one of the funnest ways to do it," Phelps said of closing out his career with a relay.

"Being able to step up with these four guys and continue this streak is important to us.

"I just said before we went out, we've got to want to win, let's just go out and do it," Phelps said.

Their smile-filled medal ceremony was followed by a special presentation to Phelps, who received FINA's lifetime achievement trophy and walked one last victory lap round the pool.

"I am feeling sort of emotional, kind of bittersweet," Phelps' longtime coach Bob Bowman confided to AFP, but the swimmer he has guided since childhood was emphatic that it was time to move on.

"I have achieved everything I wanted," Phelps said. "If you can say that about your career, there is no need to look forward. Time to move on to other things."

In what he had vowed was his final race, the four-time Olympian took his career medals tally to 22. The 18 gold include the stunning eight gold in eight events he won in Beijing four years ago, and he also owns two silver and two bronze.

Although Phelps wasn't the same swimmer he was in Beijing, he said he'd treasure his memories of London.

"The memories from this week will never go away," he said.

China's Sun Yang offered a worthy curtain-raiser to Phelps' finale as he shrugged off a heart-in-mouth moment at the start to destroy the field and win the 1,500m freestyle gold in a world record time, and America's 4x100m medley women also won in a world record.

Sun shook off a heart-in-mouth moment at the start, when he slipped and hit the water as the other swimmers stood up before the start.

He wasn't charged with a false start that would have ended his night, and after the public address announcer instructed the crowd to maintain silence, a seemingly shaken Sun joined the rest of the field in returning to the blocks and powered to a win in 14:31.02, bettering the previous world record he set last year at the world championships in Shanghai.

"I thought I was going to be disqualified," admitted Sun, who said he couldn't hear the starter properly over the crowd noise.

"I didn't expect the false start and I was very worried about being disqualified," added the swimmer who beat the water in joy before breaking down in tears upon seeing the result on the scoreboard.

Once away, Sun was never challenged as he became the seventh man, and the first since Russian distance freestyle great Vladimir Salnikov in 1980, to win both the 400m free and 1500m free at the same Olympics.

Sun's triumph in the 400m free last Saturday made him the first male swimmer from China to claim Olympic gold and he earned silver in the 200m free.

More than eight seconds back, Canadian Ryan Cochrane took silver in 14:39.63 and Beijing champion Oussama Mellouli earned bronze in 14:40.31.

The US quartet of Missy Franklin, Rebecca Soni, Dana Vollmer and Allison Schmitt won the women's 4x100m medley relay in a world record of 3:52.05.

Franklin, 17, claimed her fourth gold of the Games as part of the formidable line-up. She, Vollmer and Soni had all set individual world records here.

Australia took silver in 3:54.02 and Japan claimed the bronze in 3:55.73.