Michael Phelps is a swimming machine. The word “machine” has Greek roots, referring to a contrivance, an engine. Phelps, then, is a H2O machine. The medals clanging around his neck in Rio – five golds and one silver – more than the total tally of hosts Brazil and 17th on the current medals table, 27 in total, tied overall with South Africa, are overt proof. But to dehumanise Phelps as a mere machine – or medal stat – is just wrong.

No, Phelps is a transcendent athlete, the United States’s flag-bearer, the protagonist of a Baltimore sporting fable, and, arguably, the greatest Olympian of our times. Maybe even of all times. His farewell at Rio’s intimate and colourful swimming stadium on Saturday was one of the great spectacles, a moment of the highest order.

The denouement

For one last time on Saturday, Phelps walked out to the pool. It was the men's 4x100 metre medley relay.

He ambled along in his cool knee-length swim parka in a blue flag with red chevrons on the chest and stripes on the hood, without the headphones or death stare that had emanated when his South African rival Chad Le Clos shadowboxed in the waiting room earlier this week.

For a while, Phelps did not take off his parka at all. He stood solemnly at the back of the quartet. Ryan Murphy opened up a huge lead for the US, with a world record in breast-stroke, 50.85 seconds, but Great Britain pegged them back. Phelps, America’s third swimmer with the butterfly, remediated. As he touched the wall, the US had a 0.5 seconds lead.

And so, after 11,800 meters covered at 63 Olympic races, to the denouement of Phelps’ career. In encouragement, he clapped as Nathan Adrian traversed the water. The US had a commanding lead and never looked like relinquishing it. Freestyler Adrian swam the last leg in 46.74 seconds. The USA had won, with Great Britain and Australia completing the podium.

His last bow

It was gold medal number 23 for Phelps, and fittingly won with an Olympic record, 3:27.95 minutes. Phelps smiled, but there was no hyperbole to his celebration, no sense of extravaganza or exuberance to his jubilation – a pat on the back here and there.

Then, with a devastating finality, the time had arrived for Phelps to leave the pool. He hunkered, zooming out, in solitude for a split second before lifting his arms, a last salute to his fans. Tears welled up in the great swimmer’s eyes.

In Rio, Phelps’s journey, both sporting and personal, often treacherous and devious, has come full circle. From the dark days where he was photographed holding a bong, arrested for driving under the influence leading to emotional torment and time spent in rehab, the American was a picture of serenity and family life at Rio, with an adorable three-month old son, Boomer, cheering from the stands.

Leaving a legacy

Last Tuesday, in the pool, Phelps had excelled yet again, demonstrating his all-round qualities. In the 200 metre butterfly, he won a sublime gold. In Sydney 2000, he had finished fifth in the same event. On the medals podium, Phelps, in a rare moment of public vulnerability, became teary during the American national anthem. In his world, his 20th gold medal was just another ordinary feat, a quasi footnote in an empyreal career, but his post-race reaction – Phelps’s face was deadpan, but his gesticulation, arms aloft, back and forth, almost chest-pumping, wagging his fingers – revealed the intensity of his swimming, the relish in winning his signature race.

Soon after, he anchored the 4x200 metre freestyle relay. Conor Dwyer, Townley Haas and Ryan Lochte swam the first three legs. Phelps’s last leg was another personal and collective coronation. At 31, Phelps was still a superlative swimmer.

On Thursday, with his 13th individual gold medal in the 200 metre individual medley, he broke a record that had stood since 152 BC, when Leonidas of Rhodes won 12 individual events over four Ancient Olympic Games. Phelps though showed little regard for historical niceties and simply powered past Leonidas.

Yet there was a twist in his golden streak in the “Marvellous City”. On Saturday, Joseph Shooling from Singapore – whom Phelps referred to as “a kid” – defeated the American in a thrilling 100 metre butterfly final. Phelps finished joint third on 51.14, together with Le Clos and the Hungarian Laslzo Cseh.

The back story to Schooling’s rise – his teenage admiration for Phelps – was testimony to the American’s profound influence on his sport, sparking the transformation from a traditional Olympic sport to a global blockbuster. Above all, Phelps, in the glorious but often wretched theatre of humanity that the Olympic Games are, delivered sporting prowess and unadulterated joy. The most decorated Olympian did so again, on Sunday night in Rio – for one last time.