Roger Federer feared he was heading home to the Swiss alps, before surviving seven match points and sealing a remarkable 15th Australian Open semi-final berth.
Hampered by a groin injury, the six-time champion appeared headed for a shock exit against unseeded American Tennys Sandgren on Tuesday night, before rallying for a miraculous 6-3 2-6 2-6 7-6 (10-8) 6-3 victory.
The 38-year-old 20-time Grand Slam champion earned a record-extending 46th major semi-final appearance.
Bidding for his first final-four spot and hoping to become the first US man in the Open semis since Andy Roddick in 2009, Sandgren had seven match points in the fourth set.
But the moment got the better of the world No.100, while Federer - playing in his 1512th career match - held his nerve.
"I think I got incredibly lucky today," Federer said. "I don't deserve this one, but I'm standing here and I'm obviously very, very happy.
"I was just hoping that maybe he was not going to smash the winner, you know, on that one point, that he would maybe keep the ball in play."
Federer needed a medical time-out in the third set, but didn't believe the injury would hinder his chances of a record-equalling seventh Open crown.
"I've got nothing to do tomorrow and then I play at night, so you do feel better in a couple of days and then you just never know again," he said.
"With these lucky escapes, you might play without any expectations anymore, because you know you should really be skiing in Switzerland.
"So there you go - I'm lucky to be here and I will make the most of it."
Federer looked in full control early, taking the first set in 34 minutes, but Sandgren broke early in the second set and the wheels started to fall off, as a hush fell over the venue.
Down 0-3 in the third set, the world No.3 was angered, when he received a code violation warning, after a lineswoman reported a verbal obscenity. He then called for a physio and left the court for treatment.
Federer, who has never retired mid-match, said he was determined to see it out.
"I believe in miracles - it could be rain, there could be stuff, I don't know. It wasn't bad enough that I thought I was going to get worse, it was just stiff and tight.
"I thought I would just let him finish me off in style - and he didn't."
Sandgren had three match points on Federer's serve at 5-4, but was unable to find the winner, with the set then going to a tiebreak.
Locked at 3-3, a ball kid bizarrely ran into Sandgren's leg at the changeover, with the American taking time to walk off the blow.
Unrattled, he steamed ahead to lead 6-3, but again couldn't close it out.
He had one final chance at 8-7, but Federer showed his poise to level and then clinch the set.
A deflated Sandgren was unable to lift in the fifth, with the 20-time major champion breaking to go ahead 4-2, before sealing victory.
Federer will face Novak Djokovic for the 50th time in a mouthwatering semi-final, after the defending champion outlcassed Milos Raonic 6-4 6-3 7-6 (7-1).
"Draws are not getting easier," Federer said. "I'll have to play better than I did today, otherwise I really am going skiing."
Djokovic pays tribute to fallen friend Kobe Bryant
An emotional Djokovic paid tribute to NBA great Kobe Bryant, after setting his victory over the Canadian.
The Serbian superstar put on a clinical display on Rod Laver Arena, prevailing 6-4 6-3 7-6 (7-1).
The No.2 seed will face off against Federer for the 50th time in their storied rivalry, which stands at 26 wins for Djokovic and 23 victories for the Swiss master.
Djokovic was moved to tears on court, as he spoke about his fallen friend, who died with daughter Gianna and seven others in a helicopter crash in the Los Angeles hills on Sunday.
"I don't know what we could say... it really caught us by surprise," Djokovic said. "He was one of the greatest athletes of all time.
"He inspired myself and many other people around the world. I had the fortune to have a personal relationship with him, and when I needed some advice and some support, he was there for me.
"He was my mentor, my friend, and it's just heartbreaking to see what has happened to him and his daughter."