Reigning Olympic champion and world record-holder Phelps won his heat, but the leisurely pace of 4min 13.33sec saw him scrape into the final in the eighth and last spot.
Hungarian Laszlo Cseh, who earned silver behind Phelps in Beijing and bronze in Athens, was second in that heat and didn't make the final.
"I was slower here this morning than I was four years ago, but you can't win the medal from the heats," Phelps said.
Lochte, who has established himself as a threat to Phelps in both the 200m and 400m medleys, was content to finish second in his heat behind South African Chad le Clos.
Le Clos's 4:12.24 was second-fastest of the morning, and Lochte was third-fastest of the day in 4:12.35.
Meanwhile, Hagino was delighted to set a Japanese record.
"I already broke the national record in April, so I just beat my personal best," he said. "There are a few things I want to improve on in the afternoon, I can definitely improve in the last quarter of the race."
Despite Phelps' lowly qualifying position, Lochte said he'd be keeping an eye on his compatriot.
"It's a tough competition, he's in the final and you can't count him out," Lochte said, adding that the heats in the grueling four-stroke event were all about getting into the final.
Phelps isn't trying to match his great haul of China – eight gold medals in eight events – but he does have a chance to make more Olympic history.
As the two-time defending champion in all four of his individual events – the 100m and 200m butterfly and 200m and 400m individual medley he could become the first male swimmer to win the same Olympic event at three successive Games.
If he doesn't do it in the 400m medley on Saturday, Japan's Kosuke Kitajima could be the first.
Kitajima, the two-time defending champion in both the 100m and 200m breaststroke, was due to open his campaign in the 100m breaststroke heats on Saturday.
Other events on the opening day of competition at the London Aquatics Centre included the men's 400m freestyle, the women's 400m medley, the women's 100m butterfly and the women's 4x100m freestyle relay.
Phelps, whose 16 total Olympic medals include 14 golds, needs just three medals to surpass Soviet gymnast Larisa Latynina for the most in an Olympic career. – Sapa-AFP