Federer is playing his first tournament since the US Open, where he destroyed Goffin for the loss of just four games, but the Belgian provided much stiffer resistance this time around.
Having forced the first break point in a lengthy Federer service game at 1-1, he finally broke to lead 6-5, but was not able to convert any of his three set points.
Tennis
'It is time to kick out the Big Three' - Harris says next generation are here to stay
YESTERDAY AT 14:19
Instead, Federer forced a tie-break and a saved two more set points before triumphing 9-7 with 70 minutes gone.
There was an air of inevitability from that point on, Goffin having only beaten the all-time great once in his last 10 meetings, but once again the opportunity was there - the outcome might have been different had he converted more two of his five break-point opportunities.
Just one break of serve and one match point was all that the Swiss needed in the second set as he managed to get off court five minutes before the match clock hit two hours.
He will now play Alexander Zverev for a place in the semis after the fifth seed beat Russian Andrey Rublev 6-0 7-6(4), while Daniil Medvedev and Novak Djokovic are both potential opponents if Federer wants to seal a third Shanghai title.
In the top half of the draw, Djokovic needed just 76 minutes to complete his last-16 victory over John Isner as the big-hitting American failed to create a single break point opportunity.
The world No 1 will now face Stefanos Tsitsipas as he seeks to defend the title he beat Borna Coric to win 12 months ago.
US Open
'It's not acceptable' - Djokovic gets 'unfair treatment' compared to Federer and Nadal, says Becker
YESTERDAY AT 13:31
Laver Cup
Discovery Sports secures decade-long deal to show Laver Cup exclusively across Europe
YESTERDAY AT 09:36