The 29-year-old Queenslander took advantage of an out of sorts Federer who was forced to sweat as the humid New York conditions and an unusually inconsistent serve took their toll.
Millman, ranked 55th in the world entering the match, was as shocked as the New York crowd with the result. Federer had been 40-0 against players ranked outside the top 50 at the US Open.
"A little bit of disbelief, he's been a hero of mine," Millman said after being asked how he felt defeating the greatest tennis player of all time. "He's definitely not at his best, but I'll take it."
He will now play Novak Djokovic in the quarterfinals on Thursday morning (AEST).
The Swiss maestro was caught off guard in the very first game of the match as Australia's last man standing squeezed his way to break point. But a searing ace allowed Federer to survive as he ran away with the first set 6-3.
Millman found some gas in the second set, pinning Federer to the wall in a marathon second game. The 20-time grand slam champion missed 19 of 22 first serve attempts and was forced to defend seven break point opportunities in a 14-minute epic.
Fans noted the amount of sweat on Federer's shirt after the colossal game, with some labelling it is his worst service display in years.
Millman missed the opportunity at an early break and Federer looked to make him pay.
But despite leading 5-3 and then 5-4 40-15, he couldn't put the Aussie away and Millman reeled off three consecutive games to pinch the second set 7-5 and square the match.
The fighting performance continued early in the third as Millman defended a break point to hold serve in the opening game. He worked his way to a 2-1 lead but a love service game from Federer evened out the equation.
Millman hit back and won his seventh of the past nine games to bring it to 3-2. The tug-of-war continued as each player dominated their respective service games to bring the third set to a tense tiebreak.
Before the match, Federer had a word of encouragement for Millman, who has practised with him in Switzefland.
"He's just come to Switzerland to train with me before the grass-court season so we know each other quite well. (He's) a super friendly guy, and I'm very happy for him that he's gotten so far.
"But now I'll try to stop him, so we'll see how it goes."
Millman said the Swiss star was "always someone he looked up to" before their fourth round clash.
Federer could have been forgiven for looking ahead to the quarterfinals, where nemesis Novak Djokovic awaits.
It would be their earliest meeting in a Grand Slam since 2007, when Federer defeated Djokovic to reach the Australian Open quarters.