The third seed had come back from 4-8 in a deciding tie-break to beat John Millman in round three, but that was put into the shade by his efforts against Tennys Sandgren.
The 100th-ranked American had seven match points in the fourth set of the biggest match of his life but Federer saved all of them and went on to win 6-3 2-6 2-6 7-6 (8) 6-3.
“Honestly, when they told me seven, I was like, ‘What?’ I thought it was three,” said Federer. “I just said, ‘If he can belt a backhand down the line, or run around and go huge, he’s willing to take a chance’, because you just don’t know if you’re going to get another opportunity for a match point like this.”
An emotional Novak Djokovic paid tribute to Kobe Bryant as he continued his march through the Australian Open draw with a straight-sets victory over Milos Raonic in the quarter-finals.
Djokovic was good friends with the basketball star, who was killed in a helicopter crash on Sunday, and he came out for the match on Rod Laver Arena looking like a man on a mission in a 6-4 6-3 7-6 (1) victory.
The defending champion broke down as he spoke about Bryant afterwards, saying: “I don’t know what we could say. It really caught us by surprise.
“He was one of the greatest athletes of all time, he inspired myself and many other people around the world. I had that fortune to have a personal relationship with him over the last 10 years.”