You have to go back a long way to find a record Michael Phelps hasn’t already broken. After 21 Olympic golds, 26 World Championship titles, and 38 world’s best times, you’d think there would be none left. But Olympic statistician Bill Mallon found a new one just this week. Phelps’ 22nd Olympic victory, in the 200m individual medley, was his 13th in an individual event – the other nine were in relays – and that, ladies and gents, is the most solo wins by any man or woman in history. All history. Not just the modern Olympics, but the ancient Games too. Phelps has now overtaken Leonidas of Rhodes as the most decorated Olympian of this, that, and every era. Leonidas, as every self-respecting sports fan knows, did the sprint triple in the stadion, the diaulos, and the hoplitodromos, at four Olympics in a row between 164 and 152 BC. Or 2,168 years ago.

This was Phelps’ fourth consecutive 200m medley title, the truest test of the best all-round swimmer in the world. Leonidas was a multi-talented man himself. He competed in the stadion, a short sprint lap of the stadium; the diaulos, run over twice the distance; and the hoplitodromos, when he and the other runners had to wear a helmet, heavy armour and a bronze shield. Until Leonidas did it, it was thought to be impossible for any man to win all three. As the second-century sports hack Philostratus the Athenian wrote in his Gymnasticus, Leonidas’ “versatility made all earlier theories on runner’s body types obsolete”. Twenty-one centuries later, Phelps has also redefined his sport, and left his competitors similarly redundant. He won in 1:54.66 and by almost two whole seconds, by far the largest margin in any of his four finals in this event.

Leonidas aside, Phelps’ more immediate concern was the man in the very next lane over, his old pal Ryan Lochte. This was the fourth time Lochte and Phelps have contested this event, and the final chapter in the longest and most entertaining rivalry in Olympic swimming. It was also the fourth time Lochte has lost. “I guess,” Lochte said before the race, “you would say I’d be like the Michael Phelps of swimming if he wasn’t there.” We should spare him some space, since most likely this was also his farewell to the Games. Lochte has 12 Olympic medals himself, which is more than Mark Spitz, and makes him the second-most decorated swimmer in history. And he’s parlayed that success into a second career as the designer of his own clothing label (“Ralph Lauren, but with a little edge to it”), and a third as the star of the E! reality TV show What Would Ryan Lochte Do?

Michael Phelps holds up four fingers alongside his gold medal signifying his historic achievement. Photograph: Clive Rose/Getty Images

Most memorably, Lochte tried to trademark his personal catchphrase: “Jeah”. He was unsuccessful. So was the TV show, which was soon cancelled. As may have been his fledgling friendship with Prince Harry after the two of them were pictured at 3am cavorting in a Las Vegas pool full of what headline-writers described as “bikini-clad babes” one night in 2012. It’s all good, for Lochte at least. Harry on the other hand was pictured playing strip billiards later that weekend, and had to apologise for letting his family down. Lochte’s friendship with Phelps has turned out to be longer lasting. And 10 minutes before the start they were still cracking jokes and cackling in the warm-up room.

There was a version of this race in which Lochte actually managed to finally beat Phelps. Sadly it was only on Canadian TV, where the commentators managed to confuse the two, so called the win for the wrong man. Lochte actually finished fifth, after fading away in the final 100m. Thiago Pereira, a local, led through the butterfly and backstroke, but Phelps, as inexorable as the incoming tide, pulled so far ahead on the breaststroke leg that no one got close during the final freestyle. In the end it was a procession. The fact that Lochte struggled so much emphasised how incredibly well Phelps has handled himself this week. There’s only a 10-month age gap between the two of them, but for Lochte, struggling with injuries, this felt like one meet too many. He explained: “I just didn’t quite have it.”

Instead, the silver went to Japan’s Kasuke Hagino and the bronze to China’s Shun Wang. One’s 21 and the other 22, both around a decade younger than Phelps – another couple of talented kids who, like almost every other contender in butterfly and medley swimming these last 12 years, were unable to beat him when it mattered most. Phelps is feeling his age, but he’s not giving in to it. “My body is in pain, my legs are hurting, I’m tired,” he said. “I was in a hurt of pain that last 50, I just forced myself to stay under water and spun my wheels as fast as I could.” Down the stretch, he started to think thought about an inspirational message he’d been sent by the old Baltimore Ravens linebacker Ray Lewis. He wouldn’t let on what Lewis had said, but whatever it was it pushed him to the line.

How does Phelps do it? “The biggest thing for me through the meet so far is I’ve been able to finish how I wanted to,” he explained. “I’ve been able to come back and I’ve been able to achieve things I’ve only dreamt of.” He won’t miss swimming the 200m medley. But he will miss the winning. “Getting out of the pool may take a little more energy, and it might be a little bit harder, but it is just as sweet standing on top of the podium listening to the national anthem play, and that’s something that when I retire I will miss. Because every time I hear the national anthem there are so many memories going through my head, and pretty much every time I hear it I cry.”