It marked Federer's earliest US Open exit since he fell in straight sets to Tommy Robredo in the fourth round in 2013.

Federer had set points in both the second and third sets, but troubles with his serve infected his entire game and 77 unforced errors doomed the 20-time Grand Slam champion in the face of a determined attack from Millman.

"I'm probably in a little bit of disbelief," Millman, 29, said after three hours and 35 minutes in the cauldron of Arthur Ashe Stadium.

"I have so much respect for Roger and everything he's done for the game. He's been a hero of mine."

Federer took the opening set courtesy of a break in Millman's first service game.

But Federer's first service game in the second -- in which he battled 14 minutes and saved six break points -- proved prophetic.

Federer broke first on the way to a 5-3 lead in the set, but Millman won the last four games, breaking Federer twice.

Federer wasted two set points in the 10th game, giving Millman a break chance when he missed an easy volley then double-faulting on break point.

Federer upped his game in a tight third set, and had the first chance to claim the set at 6-5 in the tiebreaker. He netted a service return, and Millman converted his second set point to seize a two sets to one lead.

When the Swiss great broke for a 4-2 lead in the fourth the Ashe crowd were on their feet.

But he gave the break back in the next game after slamming an overhead into the bottom of the net on game point.

They went on serve the rest of the way to the tiebreaker, where two of Federer's 10 double faults, followed by a backhand into the net and a wayward forehand gave Millman a 6-1 lead.

Federer clawed his way through two match points before slapping yet another forehand wide as Millman celebrated.

"Today he was definitely not at his best," Millman said of Federer. "But I'll take it."