Cristiano Ronaldo scored two stoppage-time headers as Portugal came from behind to win 2-1 against Egypt, who had taken the lead though Mohamed Salah's second-half strike.
Salah brought his superb domestic form to the international arena during a lively showing, and opened the scoring in the 56th minute with a sharp left-footed finish from the edge of the area.
The Pharaohs, demonstrating superb defensive discipline under Argentine coach Hector Cuper, looked primed to hold on for a famous victory until Ronaldo's late intervention.
The Real Madrid superstar first met a Ricardo Quaresma cross in the 92nd minute to head home past the previously excellent Ahmed El-Shenawy, who fumbled the ball over his line.
Moments later, he added a second when he again rose to divert a free kick into the far corner.
Ronaldo's goals take his tally up to 81 in Portugal colours, putting him third in the all-time international scoring list.
Despite losing the lead at the last, Egypt will take encouragement from a strong display in which they held their own against the reigning European champions.
The Pharaohs have been pooled alongside Russia, Saudi Arabia and Uruguay in World Cup Group A, and continue their tournament preparations with a friendly against Greece on Tuesday.
Portugal may be concerned that they weren't able to break through the Pharaohs' backline earlier, but should carry the momentum from their dramatic late comeback into Monday's fixture against the Netherlands in Geneva.