Roger Federer battled back from the brink for the second time in this Australian Open to defeat Tennys Sandgren 6-3 2-6 2-6 7-6 (8-6) 6-3 and reach the semi-finals.

This comeback was even more dramatic than his third-round victory over John Millman, where Federer recovered from 8-4 in the deciding tie-break.

Here, he was physically below his best, taking an off-court medical timeout in the third set, but he still somehow managed to save seven match points in the fourth on his way to victory.

Federer was struggling to move to his forehand side and looking nothing like the player who has won 20 Grand Slam titles.

American Sandgren, ranked 100 and playing in the biggest match of his life, had three chances at 5-4 in the fourth set but made unforced errors on all of them.

He then led 6-3 in the tie-break and had a further chance but Federer, who has never retired from a professional match, simply refused to be beaten.

He loosened up a little and forced a set point on his own serve, wagging his finger as Sandgren sent the ball flying long.

And Federer ensured those heroic efforts were not in vain, freeing himself up to win the fifth set after three hours and 31 minutes.

We need your consent to load this YouTube contentWe use YouTube to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences

The 38-year-old seemed to have had his major scare against Millman, although he was still far from his best against Marton Fucsovics in round four, fighting back from a set down.

Both those matches were played at night, and the sunshine seemed to help Federer as he eased to the first set against Sandgren, who was looking to become the lowest-ranked man to reach the semi-finals here for nearly 30 years.

But Federer's problems began when he dropped serve in the second game of the second set, his usually-reliable forehand breaking down with alarming regularity.

He was furious to receive a warning in the third game of the third set after a line judge reported him swearing, but that was a trivial matter compared to what was going on with his body.

The Swiss revealed afterwards he was struggling with a tight groin, and it seemed highly unlikely he would be able to fight through it.

But fight he did, and he will now face great rival Novak Djokovic in the last four on Thursday.

"Got to get lucky sometimes, I tell you that," Federer reflected in his on-court interview afterwards.

"Those seven match points, you're not in control. I was just hoping he was not going to smash the winner, and if he missed one or two, who knows what he is thinking about.

"I got very lucky. As the match went on I started to feel better again and the pressure eased off.

"I don't deserve this one but I'm standing here and I'm very very happy."

We need your consent to load this YouTube contentWe use YouTube to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences

Djokovic's progress to the semi-finals has been far more straightforward.

His 6-4 6-3 7-6 (7-1) win over Milos Raonic means that he hasn't dropped a set since losing the first set in his opening match in Melbourne.

An emotional Djokovic paid tribute to the late basketball star Kobe Bryant, who he was friends with, and he came out for the match on Rod Laver Arena wearing a jacket bearing the initials KB, Bryant's numbers eight and 24 and a heart.

The only real concern on court for the defending champion came in the third set when he began to experience problems with his contact lenses.

Djokovic took a medical timeout and looked flustered as he continued to seek help from the trainers, but that did not stop him finishing off the match in a tie-break.

Raonic had not lost a set all tournament, defeating Stefanos Tsitsipas and Marin Cilic in the last two rounds, but he took a 0-9 record against Djokovic into the contest and soon found his mighty serve under huge pressure.

The Canadian frustrated Djokovic by saving eight break points but he finally took one to claim the first set.

The second seed broke serve again in the fourth game of the second set and, although Raonic managed to hold through the third, the tie-break was one-way traffic.

Looking ahead to the meeting with Federer, Djokovic said: "Obviously tremendous respect for Roger. He's been one of the all-time greats and definitely one of my two biggest rivals. The match-ups against Roger and Rafa have made me the player I am today.

"I hope to get to at least one match point. It was quite amazing what he has done on the court today. It's not the first time, that's why he is who he is. Let the better player win." 

The defending champion broke down as he spoke about Bryant, 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.

"When I needed some advice and support, he was there for me. He was my mentor, my friend, it's just heartbreaking to see what has happened to him and his daughter. It's unbelievable."

We need your consent to load this YouTube contentWe use YouTube to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences