Michael Phelps Michael Phelps

[SPOILER ALERT: The following story reveals the outcome of Saturday's Olympic swimming finals.]

Michael Phelps' storied career came to an end Saturday — and he went out in style.

The swimming star and most decorated Olympian of all time took his final victory lap, winning the 4x100-meter medley relay in London with teammates Matt Grevers, Brendan Hansen and Nathan Adrian in 3:29.35. Phelps' final Olympic medal tally: 22 medals (a record 18 gold, two silver, two bronze). If he were a country, he would be tied for 54th place with India on the all-time list.

Olympics: The top moments (so far!)

During the medal ceremony, Phelps was given a trophy by FINA, swimming's governing body, that was engraved with: "To Michael Phelps, the greatest Olympic athlete of all time." 

Japan won silver (3:31.26) and Australia won bronze (3:31.58).

The U.S. men have never lost the medley relay at the Olympics and entered this one as the overwhelming favorite. The lineup featured Olympic champs in three of the strokes (backstroker Grevers, butterflyer Phelps and freestyler Adrian) and a bronze medalist and former world record-holder in the other (breaststroker Hansen). The U.S. was in second behind Japan when Phelps, 27, jumped in, but he put the U.S. back in front by the end of his fly leg.

Phelps, who entered in seven events in London versus the record eight he won in Beijing, started off the Games slugglishly, finishing fourth in the 400-meter individual medley, an event he didn't start training for until this year. After nabbing the first two silvers of his career, he won his first gold in London in the 4x200-meter freestyle relay for his 19th medal to dethrone Soviet gymnast Larisa Latynina as the most decorated Olympian. He followed it up by becoming the first male swimmer to three-peat in an individual event, doing so twice in the 200 IM and the 100 fly.

Olympics Week 1: The best tweets

Phelps, who insists he won't come out of retirement to compete in Rio, leaves London with six medals, the most of all swimmers. Ryan Lochte, his friend and chief rival who says he will aim for Rio, reaped five medals, as did Phelps' training partner Allison Schmitt and Missy Franklin. Franklin, 17, won her fourth gold of the Games, to go with a bronze, in the women's 4x100 medley relay with fellow London champs Dana Vollmer, Rebecca Soni and Schmitt in world record time (3:52.05).Overall, the U.S. dominated Olympic swimming once again. The Americans finished with 30 medals, including 16 gold. (They won 31, with 12 being gold, in Beijing.) Japan is second with 11 medals.Do you think Phelps is the greatest Olympian of all time?