Roger Federer pulled off one of the greatest escapes of his career Tuesday, saving seven match points to come from two sets down and beat Tennys Sandgren for a place in the Australian Open semi-finals.

In a drama-packed match, the normally ice-cool Swiss was slapped with a code warning for swearing and needed a rare medical timeout for a groin injury before winning 6-3, 2-6, 2-6, 7-6 (10/8), 6-3.

The six-time champion's reward is a showdown against either long-time rival Novak Djokovic or big-serving Canadian Milos Raonic.

"I don't deserve this one, but I'm standing here and obviously very happy," said Federer, 38, who became the oldest man in 43 years to make the last four at Melbourne Park after Ken Rosewall.

"I just said (to myself while losing), I believe in miracles," he added.

"I got incredibly tonight, today -- I don't even know what time it is. I'm lucky to be here and might as well make the most of it (in the semis)."

The victory was his 102nd at Melbourne Park, surpassing his tally at Wimbledon to make the Australian Open his most successful Slam in terms of matches won.

In two decades of playing the Australian Open, he had never lost to a player ranked as low as Sandgren's 100 since 54th-ranked Arnaud Clement beat him way back in 2000.

But the unheralded American was always going to be a danger to the 20-time Grand Slam winner, having already beaten eighth seed Matteo Berrettini and 12th seed Fabio Fognini.

And he gave the Swiss star a massive scare.

Roger Federer
Roger Federer saved seven match points to make the Australian Open semi-finals Photo: AFP / DAVID GRAY

Both players fought off break points against their opening service games as they sized each other up.

But it was only a matter of time before Federer broke and it came in the sixth game as he began figuring out Sandgren's game, forcing errors as he took the set.

But Sandgren wasn't ready to surrender, breaking Federer for a 2-0 lead in the second when the world number three sent an overhead long.

The composed American broke again with Federer's touch abandoning him, sending down 15 unforced errors.

Playing in the mid-afternoon sun, he continued to struggle in the third, broken in his opening service game with the crowd stunned into silence.

Federer was rattled. He worked three break points when 2-0 down and when Sandgren saved two of them, the Swiss was warned for an audible obscenity, reported by the line judge after he dropped an f-bomb.

The normally unflappable star confronted the umpire and then lost three more points, again having words with the official before calling for a physio and taking a near nine-minute medical timeout.

Federer returned to hold serve but his movement was hampered and he never threatened, losing the set with another 15 unforced errors.

He grimly hung on in the fourth set, saving three match points at 5-4 and it went to a tiebreaker where more drama was in store as a ballkid collided with Sandgren at the changeover.

Federer incredibly saved another four match points before winning the tiebreak 10-8, sending the crowd into a frenzy.

His confidence sky-high, he rolled through the deciding set for a famous victory to reach the Melbourne semis for a 15th time.

Copyright AFP. All rights reserved.