CNN  — 

He said after the match that he believes in miracles, and Roger Federer needed exactly that to stay alive at the Australian Open.

The Swiss saved seven match points against American Tennys Sandgren as he prevailed 6-3 2-6 2-6 7-6 6-3 in an epic encounter on Rod Laver Arena.

Last week, Federer came from behind in a super tie break against John Millman, but this time his nerves were tested to a new extreme.

Visit CNN.com/sport for more news, videos and features

Signs that the 38-year-old was feeling the pressure surfaced in the third set as he was handed a code violation for an expletive after sinking a backhand into the net.

Federer celebrates after victory against Tennys Sandgren in the Australian Open quarterfinals.

The match seemed beyond his reach in the fourth set, but he clawed his way out to earn a semifinal against defending champion Novak Djokovic.

“You’ve got to get lucky sometimes,” said Federer.

“In those seven match points you’re not under control. It may look that way but I was just hoping that he wasn’t going to smash the winner on that one point … I think I got incredibly lucky today.”

This was one that got away for Sandgren, ranked 100 in the world and playing in his second grand slam quarterfinal.

READ: Rafael Nadal and Nick Kyrgios pay tribute to Kobe Bryant

Former Australian tennis player Margaret Court poses with a replica of the trophy to commemorate 50 years of her Australian grand slam win before the start of men's singles match between Spain's Rafael Nadal and Australia's Nick Kyrgios on day eight of the Australian Open tennis tournament in Melbourne on January 27, 2020. (Photo by Greg Wood / AFP) / IMAGE RESTRICTED TO EDITORIAL USE - STRICTLY NO COMMERCIAL USE (Photo by GREG WOOD/AFP via Getty Images)
Aus Open Day 9: Margaret Court protested, Federer's great escape
01:39 - Source: CNN

The 28-year-old, who had never lost a five set match before Tuesday’s encounter, had three match points on Federer’s serve at 5-4 in the fourth set and four more as he established a lead in the tie break that followed.

Federer had called for the physio when he trailed in the third set, but there were few signs that he was struggling towards the end of the match as he broke Sandgren at 3-2 in the fifth to see out the win.

“I’ve played a lot of tennis throughout my life and sometimes you feel a little bit funny,” said Federer.

“I was starting to feel my groin and my leg started to tighten up and i really struggled in defense. I don’t like calling the trainer ever because it’s a sign of weakness and all that stuff – I try not to show it.”

Federer, whose last grand slam title came in Melbourne in 2018, is bidding to win the Australian Open for the seventh time.

Barty advances

Ashleigh Barty became the first Australian woman to reach the final four in 36 years as she beat Petra Kvitova 7-6 6-2.

“This is absolutely incredible, I knew I had to bring my absolute best today against Petra,” said the world No.1.

“It’s a challenge, I love it. I love testing myself against Petra. She has a way of bringing the very best out of me.”

World No. 1 Ashleigh Barty has reached the Australian Open semifinals for the first time.

The French Open champion, who is bidding to become the first home singles winner in over 40 years, will next face American Sofia Kenin.

Kenin defeated Tunisia’s Ons Jabeur 6-4 6-4 in the quarterfinals to continue her best ever run at a grand slam.

READ: John McEnroe mocks ‘crazy aunt’ Margaret Court

Djokovic to meet Federer

Novak Djokovic, meanwhile, stepped up his Australian Open title defense with a 6-4 6-3 7-6 victory over big-serving Canadian Milos Raonic.

Raonic, who has struggled with injuries in recent seasons, was bidding to reach his first grand slam semifinal since 2016.

But it was Djokovic, chasing an eighth victory in Melbourne, that controlled the encounter with strong, accurate baseline hitting andcan now look ahead to his clash against Federer.

Serbia's Novak Djokovic holds the winner's trophy during the presentation after beating Switzerland's Roger Federer during their men's singles final on day thirteen of the 2019 Wimbledon Championships at The All England Lawn Tennis Club in Wimbledon, southwest London, on July 14, 2019. (Photo by Daniel LEAL-OLIVAS / AFP) / RESTRICTED TO EDITORIAL USE        (Photo credit should read DANIEL LEAL-OLIVAS/AFP/Getty Images)
Novak Djokovic's path to greatness
03:37 - Source: CNN

The ominous sign for the rest of the draw – particularly Federer – is that Djokovic has gone on to win the title in Melbourne every time he has reached the semifinals.

“I’ve been saying this many times and I’ll repeat it again, the match-ups against Roger and Rafa (Nadal) have made me the player I am today,” said Djokovic.

“I’m grateful that I’ve had so many great matches against those guys.

“It’s quite amazing what (Federer) has done on the court today and it’s not the first time he’s done that in his career. That’s why he is who he is.

“Let the better player win.”