But with everything against him - Federer believed he had a " 3 per cent chance" of winning - the six-time Australian Open champion said he played with nothing to lose.
Surely tired, Federer's two of the last three matches leading up to the semifinal were five-set thrillers that featured multiple tiebreakers.
Two nights after saving seven match points to reach the semifinals, Federer had a chance to serve for the set at 5-4 but Djokovic broke him at love and then dominated the tiebreaker.
In a landmark 50th meeting between the pair, Djokovic ran out a dominant victor 7-6 (7-1) 6-4 6-3 at Rod Laver Arena - leaving the 38-year-old Swiss without a Grand Slam win against his rival since Wimbledon way back in 2012.
Federer received the code violation in the third set of his match against Sandgren when a lineswoman reported Federer to the umpire, Marijana Veljovic, who issued the warning.
Federer headed straight off court for another medical timeout, this one apparently for treatment to his lower back, while Djokovic also consulted the doctor and took a pill.
Davos 2020: Prince Charles meets Greta Thunberg
Isabelle Axelsson is one of the youngest delegates at Davos , where the 19-year-old, dressed in Dr. Thunberg is now taking a gap year from school to focus on her activism.
Camila wore $2m necklace with $13 Foundation to Grammys
I really feel we every had a crush nevertheless we had been every being infants about it - nevertheless we're grown now. The former Fifth Harmony singer is nominated in the best pop duo/group performance for Senorita with Mendes.
Reaction to the death of retired National Basketball Association superstar Kobe Bryant
NBA Legend Kobe Bryant was reported dead this morning from a helicopter plane crash near Calabasas in Los Angeles. Federal Aviation Administration spokesman Allen Kenitzer said the downed chopper was a Sikorsky S-76.
The second men's semi-final takes centre stage on Friday evening, with Zverev facing fifth seed Dominic Thiem for the right to take on Djokovic.
"Back in the day I feel like we could speak to linespeople", Federer said.
"Gotta go for it, you never know, but once you can see it coming that it's not going to work anymore, it's tough".
"When I was on the court at the beginning, I was really paying too much attention on his movement, what he was really doing".
'It was probably not the best mindset from me at the begging of the match I was looking at how he was moving. "And in between, it's one to forget, because you know you have a 3 percent chance to win".
It is one of Federer's more extraordinary statistics that in more than 20 years of playing at the top level he has never failed to complete a match. "I think I overall played alright". But look at the end of the day, I'm very happy.
He did gain some revenge over the Serbian in the round-robin phase of the ATP Finals a year ago, but Thursday night was their first rematch where it really mattered - on a Grand Slam stage.