Second seed Federer, who had not dropped a set in his first three matches, was uncharacteristically sloppy, committing 77 unforced errors and 10 double faults while landing just 49 percent of his first serves.
There was little sign of what was in store for the five-times champion when he took the first set with ease, before world No. 55 Millman turned the tables to win the second then held his nerve through two tiebreaks to secure the victory in three hours and 34 minutes.
While the temperature in New York hovered around 78 Fahrenheit (25C), Federer said high humidity was the problem at Arthur Ashe Stadium.
“I just thought it was very hot tonight,” Federer said. “Was just one of those nights where I felt I couldn’t get air. There was no circulation at all.
“It’s one of the first times it’s happened to me… John was able to deal with it better. He maybe comes from one of the most humid places on earth, Brisbane.
“Some days it’s just not the day where the body can cope with it.”
Millman, who trained with Federer in Switzerland before the grass-court season, was in shock at having beaten one of his idols.
“I’m probably in a little bit of disbelief,” he said. “I have so much respect for Roger and everything he’s done for the game.
“He’s a hero of mine. Today he was definitely not at his best but I’ll take it.”
Federer started well, racing through the first set and unsettling Millman by dropping the ball short.
He looked to be cruising as he opened up a 5-3 lead in the second but squandered two set points when serving at 5-4 before making two unforced errors and a double fault that allowed Millman to draw level.
The 29-year-old Australian held serve and suddenly Federer found himself serving to force a tiebreak. He cracked, double faulting again and making two more unforced errors, as Millman roared back to level the match at 1-1.
“I felt like a deer in the headlights to begin with, to be honest,” Millman added. “Roger had me on a string. He was manipulating me around the court.
“But I got out of a tough second set, really found my feet and started to be a little bit more aggressive.”
After being caught out by the drop shot earlier in the match, Millman began to read it better and improved from a single net point won in the first set to 17 from a possible 30 by the end of the match.
Federer, who won five straight titles at Flushing Meadows between 2004 and 2008, continued to struggle with his serve, double faulting twice in a row in the final tiebreak and conceding the match with a forehand error.
Next up for Millman is a quarter-final match-up against Novak Djokovic, and Federer said the sixth seed will have a fight on his hands.
“I think (Millman has) got a great backhand… When you attack there in the wrong way, he will punish you every time for it,” said the Swiss.
“I think against Novak, he just has to bring it again, try to worry Novak, hope for another hot day maybe.” (Reuters)