Egypt knocked out Morocco to reach the Africa Cup of Nations semi-finals as substitute Mahmoud Abdel-Moneim prodded home a dramatic 87th-minute winner.
Mohammed Salah had twice been denied by Munir Mohamedi, but prior to the goal Morocco missed a host of good chances.
Aziz Bouhaddouz failed to connect with a cross from two yards out, before seeing a header deflected just wide.
And Morocco defender Romain Saiss and midfielder Mbark Boussoufa were both denied by the crossbar.
Egypt go on to play Burkina Faso, who beat Tunisia 2-0 in their quarter-final on Saturday.
Egypt – the most successful side in Africa Cup of Nations history with seven titles – are yet to concede a goal in Gabon on their return to the competition after a seven-year absence.
But Morocco boss Herve Renard’s bid to become the first manager to win three Africa Cup of Nations title with three different countries is now over.
The Frenchman led Zambia to unlikely triumph in 2012, and won the 2015 title with Ivory Coast.
On a pitch that has been criticised for its poor quality, his side created the greater number of clear opportunities to score but were wasteful in front of goal and were made to pay as extra-time loomed.
From an Egypt corner that Morocco failed to clear, the ball dropped kindly to 22-year-old forward Abdel-Moneim, also known as Kahraba, who stabbed home the winner on the spin.