There are a # of GS he won where it was either an earlier round or final where the other guy clearly was outplaying him, but he somehow turned it around. 2017 AO final was even until the 5th, but Nadal had 3-1 lead so I'm including that.
2004 Wimbledon(Roddick, Final)
2006 AO(Baghdatis, Final)
2007 US Open(Djokovic, Final)
2008 US Open(Andreev, R16)
2009 FO(Haas, R16)
2010 AO(Davydenko, QF)
2012 Wimbledon(Benneteau, R32)
2017 AO(Nadal, Final)
At any point here had Federer lost one of these matches it would have seriously derailed his 'legendary career'.
Three really stand out to me.
2009 FO vs Haas. Fed down 2 sets to love. 3rd set, *30-40, make a gutsy I/O forehand winner
and never looks back.
2010 AO vs Davydenko. Davy is dominating the match 6-2, 3-1. Fed serving *1-3, 30-40, Davy about to go up double break and it's OVER. Somehow Fed saves it and rolls off 13 straight games and it's OVER.
2017 AO vs Rafa. Down 3-1 in the 5th, ANYONE would have to go with Rafa to close the deal here. For Roger to roll off 5 straight games to take the title is something he never did previously in his career in such a situation and really marks him down as GOAT.
But the scariest one of all was def 2009 FO vs Haas because if he misses that forehand, any last chance of a FO title flushed down the toilet. As we could see later, it was his ONLY shot at a French Open and he found a way to get it. Probably his most important win.