South Africa snatched the last African place for the 2020 Tokyo Olympic Games on Friday, joining Egypt and the Ivory Coast as the three African representatives among 16 nations in Japan next July and August.
South Africa qualified with a 6-5 penalty shootout victory over Ghana in Cairo after a breathtaking third place play-off.
Egypt won the U-23 Championship, beating Ivory Coast 2-1.
In the third-place playoff, Ghana twice came from behind in regular time, with the second equaliser scored on 85 minutes by Samuel Obeng, forcing the match to a shootout.
Both sides converted four of the five mandatory kicks and after Lyle Foster gave South Africa a 6-5 lead, Emmanuel Cudjoe had his penalty saved by Mondli Mpoto.
South African players and coaches hugged each other at the Cairo International Stadium while many Ghanaians slumped to the ground and wept.
Ghana also lost on penalties against the Ivory Coast in the semi-finals of the eight-nation qualifying tournament, foiling them in the first of two chances they had to reach Tokyo.
South Africa led when Habib Mohammed conceded a 15th-minute own-goal and Ghana levelled five minutes into the second half through an unstoppable Evans Mensah shot.
Kamohelo Mahlatsi put South Africa ahead a second time after 62 minutes with a close-range shot, but a dazzling Mensah dribble and a fumble by Mpoto allowed Obeng to equalise.
With extra time not part of the play-off regulations, the shootout drama began and Ghana looked the likelier winners until their fourth kick, from Fobi Kingsley, was saved.
Africa has claimed five Olympics football medals with Nigeria winning gold, silver and bronze, Cameroon gold and Ghana bronze.
Qualifiers are restricted to under-23 footballers, but the 16 finalists can include three over-age players, opening the possibility of Egypt choosing Mohamed Salah.
Unlike Europe, where Olympics football attracts little attention, some African eliminators draw 60,000-plus crowds.