NEW YORK — At least the last time Roger Federer lost in the fourth round of the U.S. Open, the upset fit the narrative.

The summer of 2013 was a summer of uncertainty and confounding losses for the Swiss champion, who struggled with a bad back as he suffered a second-round defeat at Wimbledon, a semifinal loss in Germany and a second-round tumble in Switzerland against three players ranked outside of the top 50. A round of 16 loss to Tommy Robredo in New York was unexpected, like any Federer loss against a man not named Novak Djokovic or Rafael Nadal, but understandable. There was something to make sense of.

There was no such string to grab onto just before 1 a.m. Tuesday at Billie Jean King National Tennis Center when John Millman, ranked No. 55 in the world, toppled Federer 3-6, 7-5, 7-6 (9-7), 7-6 (6-3) on Arthur Ashe Stadium. The Swiss has three titles this year, including the Australian Open. Federer also made it to the quarterfinals at Wimbledon after skipping the French Open.

In England he fell to eventual finalist Kevin Anderson. But even then, it was brutally hot at Wimbledon this summer and the fast, dry courts seemed to favor big servers. And Anderson at least had significant Grand Slam experience, having made the 2017 U.S. Open final.

But Federer, ranked No. 2 heading into the U.S. Open, was the unequivocal favorite on a stiflingly hot Monday night up against an unseeded Aussie; Federer had never lost to a man ranked outside the top 50 at Flushing Meadows and Millman didn’t have a win over a top-10 player.

On the ESPN broadcast, John McEnroe called it one of the biggest upsets in tennis history. After all, Federer has won five of his 23 Grand Slam titles at the U.S. Open. Before the loss in 2013, Federer’s most recent fall in the round of 16 came in 2003.  The 20-time major champion had no explanation other than the heat.

“Was just one of those nights where I guess I felt I couldn’t get air. There was no circulation at all,” Federer said. “I don’t know, for some reason I just struggled in the conditions tonight. It’s one of the first times it’s happened to me. … When you feel like that, everything is off. But, look, I’ve trained in tougher conditions. I’ve played in the daytime, you know, at 120 (degree heat). Some days it’s just not the day where the body can cope with it.

“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 U.S. Open. Plus conditions maybe were playing slower this year on top of it. You have soaking wet pants, soaking wet everything. The balls are in there, too. You try to play. Everything gets slower as you try to hit winners.”

Federer, seeded second and on a presumed quarterfinal collision course with sixth-seeded Djokovic before the ouster, looked uncomfortable all night. He missed an unusual amount of first serves and failed to convert three set points while Millman stayed calm and chased down seemingly every ball.

It still felt surreal until the very end. The white flag of surrender came in the fourth-set tiebreaker when Federer served back-to-back double faults, his ninth and 10th of the match. Only four times in his career has the 37-year-old hit double-digit faults at major tournaments, most recently in 2011.

His serve troubled him all night. Serious cracks in the foundation appeared in the second set’s first game, which took 15 minutes while Federer missed 18 first serves. Towards the end of the second set, Federer led 5-4 with a 40-15 edge on his serve in the 10th game, but couldn’t close it out.

“I started to find my feet a little bit I think in that second set when he served for it,” Millman said.

A rowdy Labor Day crowd that included magazine industry icon Anna Wintour, the comedian Aziz Ansari and Golden State Warriors Coach Steve Kerr cheered Federer on anyway. U.S. Open spectators hungry to get their money’s worth almost always cheer for the underdog, but Monday’s spectators were mostly behind Federer as only a few pockets of the 24,000-seat stadium stood up for Millman.

But the 29-year-old Brisbane native with no titles to his name might have won his share of fans in New York. At one point he nearly quit tennis because of various injuries that required more than one shoulder surgery and a groin surgery.

“It’s challenging financially. It’s challenging physically. It’s challenging mentally,” Millman said. “Yeah, it’s tough to start all over again a few times. But, you know, you do it. And you do all those moments in rehab, you do all that for something like this. It all becomes a little bit more rewarding.”

Having reached the first Grand Slam quarterfinal of his career, Millman now has a date with the reigning Wimbledon champion, Djokovic.

Hours earlier on the same court, the Serb sped through a much less dramatic 6-3, 6-4, 6-3 fourth-round victory of Joao Sousa, the first Portuguese man to play in the round of 16 at a Grand Slam.

Djokovic’s win came in broiling midday conditions under an extreme heat advisory — Djokovic’s face was splotchy, his cheeks were flushed with pink, and blueish-purple half moons appeared under his eyes before the first set was over. But he stretched his sterling record in the fourth round of the U.S. Open to 11-0.

The 31-year-old Djokovic will enter his match Wednesday with a 10-0 record in the quarterfinals at Flushing Meadows. He will hope history serves him better than it did Federer.

Read more tennis: