Port-Gentil - Mahmoud Kahraba's late goal allowed Egypt to beat Herve Renard's Morocco in the Africa Cup of Nations quarter-finals on Sunday as they joined Ghana in completing the line-up for the last four.
Kahraba came off the bench in the second half in Port-Gentil and stabbed home from inside the six-yard box in the 88th minute, just as extra time looked inevitable.
The dramatic finish came after the Ayew brothers, Jordan and Andre, both scored to give Ghana a 2-1 win against DR Congo in Oyem that allowed them to advance earlier in the day.
Frenchman Renard had been hoping to become the first coach to win the trophy three times with three different countries after triumphs with Zambia in 2012 and the Ivory Coast in 2015.
But instead it is Egypt who progress to the last four, their bid to win the title for a record eighth time still very much alive.
"It was a very complicated match for both teams for 94 minutes. We both had chances but we were lucky to get the goal from a dead ball," said Hector Cuper, the Argentine coach of an Egypt side who have still not conceded a goal in four matches in Gabon.
Morocco had opportunities and Romain Saiss and M'bark Boussoufa both hit the bar while Aziz Bouhaddouz somehow could not connect with Faycal Fajr's driven ball inside the six-yard box in the second half.
But Egypt were a sporadic threat in a more open second half and star man Mohamed Salah was twice denied by Munir Mohamedi in the Moroccan goal.
Extra time loomed until Morocco failed to deal with a corner into their box two minutes from time and Kahraba, who plays his club football in Saudi Arabia, capitalised.
"I am proud of all the players. One by one, honestly they were exceptional," said Renard despite the defeat.
"We must not have regrets. We must just be proud of what we have done because we have come a long way."
Egypt will now fly to Gabon's capital Libreville where they will take on Burkina Faso in the first semi-final on Wednesday.
Also read: Odds against Renard in quest for third title
- Ayews deliver Ghana -
The second semi-final on Thursday will see Ghana face Cameroon after the Black Stars got the better of an impressive DR Congo side in the midst of the rainforest in Oyem thanks to the Ayew brothers, the sons of the great Abedi Pele.
It will be a sixth consecutive semi-final for Ghana, who have not won the trophy since 1982.
Without injured captain Asamoah Gyan they saw DR Congo hit the woodwork through Dieumerci Mbokani and then went in front in the 63rd minute when Jordan Ayew fired past Ley Matampi in the Leopards' goal.
DR Congo were quickly back level thanks to a stupendous hit from midfielder Paul-Jose Mpoku, but the game ultimately hinged on a penalty award 12 minutes from time.
Christian Atsu went down in the area and Andre Ayew sent Matampi the wrong way from the spot.
"We corrected some mistakes at half-time and were a totally different team in the second half," Ghana coach Avram Grant told SuperSport.
"Both our goals were fantastic, as was the one scored by Congo, who were a well organised team."
His team will head to Franceville to face Cameroon, while for DR Congo there was disappointment after they had looked like genuine contenders to win the trophy with their performances in the group stage.
"It is hard to take but that is football. We can't win all the time," admitted their coach Florent Ibenge as the Congolese failed to match their run to the semi-finals two years ago.
"That was a miracle in 2015, we shouldn't have been there. The objective this time was to be here, and then we started to get a taste for it and thought we could go all the way.
"We haven't done that but now we must not forget the other objective, the 2018 World Cup. We have to be there."