The 22-year-old fifth seed will face Austria”s Dominic Thiem or Matteo Berrettini of Italy in the semi-finals on Saturday.
Federer, the champion in Shanghai in 2014 and 2017, was given a point penalty after losing his temper and twice hitting the ball out the court in the decider, when he was down by 3-0 and 30-15 in the fourth game.
But the 20-time Grand Slam winner had already shown his resistance in the second set as he saved five match points to force a deciding set.
Since Greek talent Stefanos Tsitsipas and Russia”s Daniil Medvedev have set their clash in the semi-finals, no matter whether Thiem or Berrettini win in the last quarterfinal, this year”s Shanghai Masters will mark the first time in ATP Tour Masters history that all the four semi-finalists were born in the 1990s.