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.
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.
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.
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.
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.”
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.
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.
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.”