11 minutes from elimination, Argentina erased a 2-0 deficit to beat Egypt 3-2 and book a World Cup quarterfinal on Saturday in Kansas City.
Messi drove the rally after a saved first-half penalty and a shot off the post, scoring his eighth goal of the tournament in the 83rd minute — his record 21st at the World Cup — to make it 2-2.
Cristian Romero started the comeback in the 79th minute, and Enzo Fernandez struck in stoppage time after Egypt had led through Yasser Ibrahim and Mostafa Zico.
The defending champions now await Switzerland or Colombia as they chase the first back-to-back World Cup titles since Brazil in 1958 and 1962.