Egypt booked an Olympic Games spot for the first time since 2012 after a vibrant second-half display saw them crush South Africa 3-0 in the semi-final of the U23 African Cup of Nations in Cairo on Tuesday.
South Africa held firm in the first half, keeping Egypt at bay with a solid defensive display.
But roared on by a sell-out crowd at Cairo's International Stadium, Egypt came on with all guns blazing in the second half and broke the deadlock in the 59th minute through a dubious penalty.
The referee pointed to the spot for a handball which occurred outside the area, with winger Ramadan Sobhi, one of Egypt's standout performers of the tournament, tucking away the penalty.
South Africa were harshly denied a penalty of their own, with the referee adjudging a foul on Kamohelo Mahlatsi to have occurred outside the box, before Egypt ensured the win with two late goals from winger Abdel-Rahman Magdi.
Jubilant scenes erupted following the final whistle, with the young Pharaohs reaching the Olympics for the 12th time -- an African record.
They will face Cote d'Ivoire in the Nations Cup final on Friday, with Ghana and South Africa battling it out in the third-place playoff, which will determine Africa's third representative in Tokyo.
South Africa's game plan looked to be going well in the first half as they shackled Sobhi to deprive Egypt of its most lethal weapon.
Chances were few and far between as both sides struggled in the final third but the controversial second-half penalty made all the difference, forcing South Africa to abandon their cautious approach.
Luther Singh rattled the bar with an angled free-kick for South Africa's best chance but Magdi ended the match as a contest six minutes from time.
He made a darting run down the right and sent in a low cross which was poorly intercepted by a defender, with Magdi pouncing on the loose ball to rifle home from close range.
A howler from South Africa keeper Darren Johnson helped Egypt complete the rout as he spilled a tame low shot from Magdi into his own net.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)