The 26-year-old Lochte, who has often had to play second fiddle to Phelps and the now retired Aaron Peirsol throughout his career, overpowered a high class field and emerged as a genuine challenger for multiple Olympics titles next year.
"It's a major confidence boost," Lochte told reporters after he won gold in one minute, 44.44 seconds. "It's the most challenging competition (I've ever raced).
"I have done all the training I can. There were a couple of bumps in the road but for most of it, I was a straight shot (and) I think it was my time tonight."
The 26-year-old Phelps, who was soundly beaten by Germany's Paul Biedermann in the event at the 2009 Rome worlds, had targeted the race as one in which he hoped to prove that his mantle as one of the best and most versatile swimmers of all time was not slipping.
He qualified fifth fastest for the final, only after a powerful surge in the final length of the semi-finals when he overtook two other swimmers, and was forced to swim from lane two, next to Lochte.
He started strongly leading at both the 50 and 100 metres mark before Lochte produced a devastating turn at the 100 metres mark when he overhauled Russia's Nikita Lobintsev and then Phelps halfway down the third lap.
The pair turned for home within 0.6 seconds of each other and Phelps looked as if he would haul in his compatriot but the 26-year-old Lochte held him off to win by just 0.35 seconds. Biedermann took the bronze in 1:44.88.
South Korea's 400 metres Olympic and world champion Park Tae-hwan finished fourth, while France's top qualifier Yannick Agnel faded to fifth after he turned for home in second place.