Rio de Janeiro: Michael Phelps brought the curtain down on one of sport's most storied careers Saturday with a dynamite relay swim to give himself a final tally of 23 Olympic gold medals.
The American, far and away the most decorated athlete in Olympic history, finished with five golds and a silver in Rio after signing off in dramatic style by coming to his team's rescue in the 4x100m medley relay.
Turning back the clock in his fifth and final Games, Phelps produced a thunderous third leg of butterfly to restore his team's lead after Britain's Adam Peaty had threatened to rudely gatecrash his party.
The hullabaloo over the 31-year-old's farewell overshadowed the achievement of the women's 4x100m medley relayers as they captured a 1,000 Olympic medal for the United States according to the US Olympic committee, dating back to 1896 when James Connolly won triple jump gold.
Even that statistic seemed to pale against the irrepressible Phelps. The same could be said for Ryan Murphy's leadoff backstroke leg, which set a new 100m world record of 51.85.
Nathan Adrian brought the Americans home to preserve their unbeaten Olympic record in the event and give them a 16th swimming gold from 32 events for the week, matching their haul in London four years ago.
An Olympic record time of 3:27.95 was lost in the emotion after the race as Phelps tearfully saluted the crowd while his beauty queen fiancee Nicole Johnson looked on sobbing as she held cradled son Boomer.
Britain took silver a second and a half back and Australia bronze, but the memory of sharing the pool with Phelps in his final race could last longer than the glow of their relay gongs.
The women's quartet of Kathleen Baker, Lilly King, Simone Manuel and Dana Vollmer made history, but were made to work.
The Americans, who failed to medal at last year's world championships, had looked in peril when two-time doping violator Yulia Efimova gave Russia the lead on the breaststroke.
But Vollmer's butterfly averted a crisis and Manuel brought them home in 3:53.13 with Australia taking silver in 3:55.00 and Denmark bronze in a European record 3:55.01
Pernille Blume, who swam Denmark's anchor leg, earlier won gold in the women's 50m free, inflicting more heartbreak on Australia's Cate Campbell after her 100m flop.
Blume won in 24.07 with Manuel adding a silver to her surprise 100m gold with a time of 24.09 and Aliaksandra Herasimenia of Belarus, the London runner-up previously banned for doping, taking bronze.
Campbell once again missed the podium, finishing fifth with sister Bronte, the reigning world champion, seventh as Australia once again came up short after a week to forget in the pool.
"It's possibly the greatest choke in Olympic history," said 100m world record holder Cate.
"It hurts. I almost needed someone to give me a Heimlich manoeuvre a couple of nights ago. Maybe I will stick around for another four years."
Campbell returned around 20 minutes later for the 4x100 medley relay but despite a fine anchor leg could not prevent the United States retaining their Olympic title.
World champion Gregorio Paltrinieri blazed to gold in the men's 1,500m in the absence of defending champion Sun Yang, who tumbled out in the heats blaming a cold.
The Italian pulverised a quality field to win in 14:34.57, narrowly missing out on Sun's world record despite being on pace to crack it until the last 150 metres.
American Connor Jaeger took silver in 14:39.48 and Paltrinieri's countryman Gabriele Detti bronze in 14:40.86.