With 79 minutes on the clock, reigning champions Argentina were 2-0 down to Egypt and looking like they were about to be eliminated.
Defender Cristian Romero then pulled one back before Lionel Messi scored the equaliser just four minutes later.
Argentina kept pushing for the winner and then a lovely looping cross from Lautaro Martinez landed perfectly on Fernandez head, nodding home the winner.
Speaking to journalist Gaston Edul after the game, the 25-year-old said: "I've just scored the goal of my life. We were on the ropes and we pushed forward with everything we know. We're a team with heart."
Fernandez and co will now face the winner of the Switzerland vs Colombia game in the quarter final on Saturday (July 11).
