A Canadian TV commentator committed the ultimate Olympic howler when he excitedly reported that Ryan Lochte had beaten Michael Phelps in the men's 200m individual medley -- before realising he had mixed up their lanes.

CBC's Elliotte Friedman mistook Phelps for Lochte right up to the finish of Thursday's race in Rio, only realising his mistake after the camera had zoomed in on a victorious Phelps.

As Phelps surged ahead on the last lap on his way to a 22nd gold medal, the commentator was convinced that it was Lochte who was bound for victory over the most decorated Olympian of all time.

"Ryan Lochte is going to beat Michael Phelps in this event in the Games and Phelps might not even make the podium!" Friedman cried, before falling silent as the race finished.

"I apologise, I got my lanes mixed up. Phelps got the gold," said Friedman after a gap of a few seconds.

As the story quickly went viral, Friedman took to Twitter to apologise again.

"I'm sorry everyone. I blew it. No excuses," he tweeted, prompting a string of sympathetic messages.