Amr Zaki's 80th minute goal sealed hosts Egypt place in the final of the African Cup of Nations, securing a 2-1 win over Senegal.
By James Copnall
BBC Sport, Cairo
Ahmed Hassan opened the scoring for Egypt in the 37th minute with a retaken penalty, after Senegal defender Frederic Mendy handled the ball.
Senegal drew level six minutes after the break through Mamadou Niang, who headed home Lamine Diatta's cross.
With 10 minutes left, Zaki powered home the winner with a close range header.
Zaki had replaced Ahmed 'Mido' Hossam, who had to be dragged away from a confrontation with Egypt coach Hassan Shehata.
Egypt's Wael Gomaa had the game's first chance, but the defender's header soared over the Senegal bar.
The West Africans held their own during the keenly contested encounter, with Amdy Faye hitting a fierce free kick just wide of the goal in the 22nd minute.
Then winger Frederic Mendy needlessly handled Mido's cross, giving away a penalty that Ahmed Hassan tucked away comfortably after being ordered to retake it for encroachment by Mohamed Barakat.
Mendy tried to make amends immediately, but Diomansy Kamara could not make good contact with his curling cross.
Neither coach made changes at half time, and Mohamed Aboutrika came close to doubling Egypt's lead, sending a curling shot onto the Senegalese bar.
In response, Senegal's raised their game and Lamine Diatta's long cross evaded the Egyptian defence, with Niang heading it back across goal and into the corner of the net.
That spurred Egypt, and Mohamed Abdelwahab's low shot only just missed the Senegalese goal.
Desperate for the winner, Shehata withdrew Mido with slightly more than ten minutes to go, sparking a furious reaction from the Egypt striker.
Mido had to be restrained by his team-mate Hossam Hassam as he confronted Shehata.
Shehata's tactical change was proved right immediately when the man who came on for Mido, Amr Zaki, headed in Aboutrika's cross for a dramatic winner.
Emad Motaeb missed three late chances for the Egyptians, and Zaki also missed an opportunity for the buoyant hosts.
As time ran out, Diomansy Kamara was brought to ground in the Egypt box but the referee waved away the desperate Senegalese pleas for a penalty.
Then substitute Issa Ba volleyed Senegal's last hope wide of the post, allowing the Egyptians to start celebrating.
Egypt will now play Ivory Coast in Friday's final while Senegal must settle for a third-place play off game against Nigeria on Thursday.
Egypt assistant coach Shawky Gharib:
"Each player is treated the same in the squad and if we wish to make a change it can be anyone we choose it to be.
"It is not their choice, it is for the benefit of the team.
"Besides Amr Zaki is a terrific player as he showed when he scored just after coming on.
"We will deal with the (Mido) problem on Wednesday.
"As regards the final well we beat them in the group stage but they had a lot of players missing and have played really well in the second round."
Senegal forward Diomansy Kamara on his penalty claim in the final moments of the game:
"Things don't work as they should do in Africa.
"It was the turning point of the game as we would have drawn level.
"However Egypt is the host nation and that is clearly the advantage."