American swimmer Michael Phelps capped off his remarkable career with a 22nd medal, as the Americans took first place in the men's 4x100 medley in London Saturday night.

The world's most decorated Olympic athlete said Saturday's race would be his last as he retires from the sport which he has dominated for the past three Olympic Games. He retires with 22 Olympic medals, breaking the previous record of 18 medals won by Russian gymnast Larissa Latynina, who competed in the 1950s and 60s.

Phelps took the gold in Friday's 100-meter butterfly after trailing several swimmers in the semifinals.

But with basketball great Lebron James and Prince William among those looking on, the Baltimore native charged ahead late to win by 0.23 seconds over South Africa's Chad le Clos and Russia's Evgeny Korotyshkin, who finished with an identical time.

That margin, while slim, was still exponentially larger than when Phelps captured gold in the same event at the 2008 Beijing Games. Phelps won that race by .01 seconds by taking a quick, final stroke to catch a Serbian swimmer gliding to the wall.

"This one was I guess a bigger margin than the last two, so a step in the right direction," Phelps told NBC after the win.

"It's a pretty cool feeling." he added.

Before Saturday's event, Phelps had won five medals at the 2012 Games, including three gold and two silver. He also won eight gold medals in 2008 and six golds and two bronze medals from 2004.