The reigning champions looked destined for a shock exit after falling 2-0 behind before scoring three goals in the final 13 minutes to book a quarterfinal meeting with either Colombia or Switzerland.
Egypt stunned the holders after 15 minutes when Yasser Ibrahim rose highest to head home Marwan Attia's inviting cross and silence the crowd at Atlanta Stadium.
Argentina had an immediate opportunity to respond after Nicolas Tagliafico was fouled inside the penalty area, but Lionel Messi's tame spot-kick was comfortably saved by goalkeeper Mostafa Shobeir. The save marked Messi's second penalty miss of the tournament, making him the first player to fail from the spot twice at a single World Cup after also missing against Austria in the group stage.
Shobeir continued his inspired display by producing a string of outstanding saves, denying Alexis Mac Allister from point-blank range, stretching to keep out Julian Alvarez's effort and watching Messi strike a free-kick against the post.
Egypt thought they had doubled their advantage in the 62nd minute when Mostafa Ziko finished off a sweeping move after being set up by Mohamed Salah. The forward celebrated wildly, even taking off his shirt, only for VAR to intervene and rule out the goal after determining Marwan Attia had fouled Lisandro Martinez in the build-up.
The decision immediately sparked debate, with television commentators questioning whether the incident fell within VAR's remit. However, under the International Football Association Board's (IFAB) Laws of the Game, VAR is permitted to review attacking offences, including fouls, handballs and offsides, in the build-up to a goal.
Ziko was not to be denied for long. Five minutes later, he capped another flowing Egyptian counterattack after Salah released Haissem Hassan down the flank before the winger squared the ball for the forward to make it 2-0.
With less than a third of the match remaining, Egypt appeared on course for one of the greatest upsets in World Cup history.
Instead, Argentina mounted a remarkable revival.
Cristian Romero headed home Messi's cross in the 79th minute to halve the deficit before the captain redeemed his earlier penalty miss four minutes later, smashing home the equaliser after Lautaro Martinez and Gonzalo Montiel kept the attack alive.
Enzo Fernandez then completed the turnaround in the third minute of stoppage time, cushioning a back-post header into the bottom corner from Lautaro Martinez's cross to seal a dramatic victory for the South Americans.
The closing moments were engulfed in further controversy.
Egypt believed they should have been awarded a penalty moments before Argentina launched the counterattack that led to Fernandez's winner after Julian Alvarez appeared to catch Mohamed Salah inside the box before winning the ball. The Egyptians also felt Alexis Mac Allister had pulled Hamdi Fathy's shirt in the same passage of play, but neither incident resulted in a VAR review.
As tempers flared, goalkeeper Mostafa Shobeir, Hamdi Fathy and Marwan Attia were all shown yellow cards, while Egypt head coach Hossam Hassan was also booked for protesting the referee's decisions as Salah tried to calm the heated exchanges.
Following the match, Hassan launched a scathing attack on the officiating, insisting his side had been denied a fair chance to progress.
'Life is unfair. The world is unfair. Okay, but why isn't there any fairness in sports? I'm not convinced by this outcome and by the way things unfolded in this match,' Hassan said.
'The referee is unfair. He's wasting the effort of an entire nation. The cup is directed towards Argentina.'
The Egypt coach also questioned why his team's penalty appeals were not reviewed.
'A penalty for us was ruled out, it was not even checked by the VAR and our second goal was, for whatever reason, disallowed,' he said.
'We have all seen the shirt pulled back and not even a VAR check. There seems to have been pressure on the Argentine side on the referee that has brought about this outcome.'
The final whistle brought contrasting emotions for the two captains.
Messi, who had endured one of the most difficult matches of his tournament before inspiring Argentina's comeback, was reduced to tears after helping keep his country's title defence alive.
At the other end, Salah and his teammates were left devastated after seeing a famous victory slip away. Egypt exited the tournament with widespread admiration for pushing the defending champions to the brink, but also with a lingering sense of injustice over the officiating that overshadowed an unforgettable contest.