Yasser Ibrahim's first-half header put Egypt in front, and Lionel Messi then saw a penalty saved by Mohamed El Shenawy either side of the break.
Mostafa Zico doubled Egypt's lead in the 67th minute after a VAR review had already chalked off an earlier effort for a foul on Lisandro Martinez. Argentina looked beaten, only for Cristian Romero to head in from a Messi cross in the 79th minute, before Messi himself struck four minutes later to level. Enzo Fernandez completed the turnaround deep into stoppage time, sweeping in the winner to send holders Argentina through to face Switzerland in the last eight.
Head coach Lionel Scaloni was overcome with emotion afterwards, cutting his pitchside interview short: "I can't look up, I'm sorry. I'm really emotional right now. What a group of players. That's it, I've got to go."
Fernandez, whose stoppage-time strike settled the tie, reflected on the years of pursuit behind the moment.
"I'd been longing for that goal for about three years, since the Qatar World Cup. Being able to experience moments like this, honestly, I thank God, I'm privileged.
"And I want to highlight my teammates - we have a phenomenal group, a group that never gives up no matter the difficulties and adversity. We're always together. Thanks to my teammates, to the coaching staff, and to everyone cheering us on here and all the Argentinians back home in Argentina. One more step forward."
Egypt boss Hossam Hassan was devastated by the manner of the defeat, insisting his side had been on the wrong end of factors beyond the pitch.
"We were better, but football is unfair," he said. "It could be a matter of marketing, they could want to make a World Cup with the champion of the last World Cup, they want Messi to exist (in the tournament). I thank my players very much. To all the Egyptians, the Arabs, the Africans, you can work hard, it's what you have to do, but sometimes there are other factors that make you struggle.
"I wish we could be happier with the loss, but with a severe loss like today I say to them (my players) be upset. We wish we could be happier. Thank God for everything but football is different from what happens in the stadium when we are playing against the world champions. There is support from all directions for the world champions. Support and marketing."
Hassan later added: "Why isn't there any fairness in sport? In football? I do not want to try to put it nicely here with beautiful wording. We have been treated unfairly today. We have suffered injustice."
Goalscorer Zico went further, singling out French referee Francois Letexier as he fought back tears.
"Referee, not fair. Unjust, unjust referee. An unjust person. An injustice that is so clear. He's wasting the effort of an entire nation. Since the beginning of the game, we were leaving the game winning 2-0 against Argentina. But the cup has already been given."
He also offered a bitter congratulations to Argentina: "I apologise to (the Egypt fans). We wanted to make them happy today. We didn't know how to do that. But, by God, it's not in our hands; it's in the hands of the referee. The cup has already been decided. Congratulations to Argentina on the World Cup. Congratulations. You don't need anything else."
Argentina now turn their attention to Switzerland in the quarter-finals, while Egypt exit having reached the World Cup knockout stages for the first time in their history.
