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.
'An extraordinary line-up' - Tsitsipas, Ruud join Nadal, Federer, Djokovic, Murray for Laver Cup
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.
Federer at 41: What's next? Will he play the US Open?
08/08/2022 AT 20:33
'That is not fair' - Lendl hopes Djokovic/Nadal GOAT debate is not 'affected by politics'
03/08/2022 AT 12:59