The 37-year-old Swiss had prioritized winning a sixth title at Flushing Meadows but was beaten 3-6, 7-5, 7-6 (9-7), 7-6 (7-3) in three hours 35 minutes, BBC Sport reported.
It is the first time Federer has lost to a player ranked outside of the top 50 at the US Open.
Millman, 29, is the only unseeded player left in the last eight of the men's draw.
"I'm probably in a little bit of disbelief," said Millman.
"I have so much respect for Roger and everything he's done for the game. He's been a hero of mine."
It was Federer's first defeat in 41 matches at the US Open against a player ranked outside the top 50.
Federer, usually so calm and collected, was flustered throughout most of the match as he complained about crowd noise and became unusually vocal during some tense moments.
Federer revealed he struggled to breathe during his shock defeat to the Australian, AFP reported.
"I just thought it was very hot tonight. Was just one of those nights where I guess I felt I couldn't get air. There was no circulation at all," said 20-time major winner Federer who was bidding to clinch the US Open for the first time in a decade.
"I just struggled in the conditions. It's one of the first times it's happened to me.
"It's uncomfortable. Clearly just kept on sweating more and more and more and more as the match goes on. You lose energy as it goes by.
"But John was able to deal with it better. He maybe comes from one of the most humid places on earth, Brisbane!"
Monday's result meant there would be no quarterfinal showdown with old rival Novak Djokovic who will now face Millman instead today.
"I knew I was in for a tough one. Maybe when you feel like that, as well, you start missing chances, and I had those," said the Swiss.
"That was disappointing. I was just happy that the match was over."
Federer believes the decision to build a roof on Arthur Ashe Stadium contributed to his problems.
The roof was open Monday, but the space above the cavernous arena has been reduced by the wings which help support the structure.
"I do believe since the roof is on that there is no air circulation in the stadium. I think just that makes it a totally different US Open," said the world number two.
"Plus conditions maybe were playing slower this year on top of it. You have soaking wet pants, soaking wet everything.
"It was just tough. I thought John played a great match in difficult conditions."
Djokovic beat Joao Sousa 6-3, 6-4, 6-3 to reach the quarterfinals.
The Serb, 31, struggled physically in the third set and went off court for a medical timeout when he led 2-1.
But he got the crucial break to take a 5-3 lead before serving out the match to secure his place in the last eight.
Despite winning in straight sets, it was not a comfortable afternoon for Djokovic.
He appeared to struggle with the humidity at the end of the second set and asked for towels of ice to be placed around his neck and on top of his head during the changeovers.
Djokovic was breathing heavily in the third set and signaled to the medical team before receiving treatment off court.
"I prefer not to talk about how difficult it was," said Djokovic. "We are blessed to play this sport and this is one of the biggest stages.
"I'm not 21 anymore. I still don't feel old but at the same time there is a biological clock that doesn't work in your favour like it does when you're 20.
"You have a team to get you ready, but sometimes you just have to survive."