Abdel Rahman Magdy scored two late goals to complete a 3-0 triumph for Egypt over South Africa after captain Ramadan Sobhy had broken the deadlock by converting a 59th-minute penalty.
Egyptian footballers last appeared at the Olympics seven years ago in London, where they fell to Japan in the quarter-finals.
The victory over South Africa maintained a perfect record by the host nation in the qualifying tournament after one-goal group victories over Mali, Ghana and Cameroon.
Ivory Coast edged Ghana 3-2 in a penalty shootout following a 2-2 draw after extra time to secure a second qualification for the Olympics, having reached the 2008 quarter-finals.
Youssouf Dao twice put the Ivorians ahead in regulation time and the second Ghana equaliser came from Evans Mensah in the second minute of stoppage time.
Ghana had several chances to win the match in extra time while Czech Republic-based Dao fluffed a last-minute opportunity to complete his hat-trick.
The shootout was won by the Ivorians when a weak fifth Ghanaian spot-kick from Owusu Kwabena was saved by Eliezer Tape Ira.
Africa has been allocated three places at the Tokyo Games and the third slot will go to the winners of a play-off between Ghana and South Africa this Friday.
There have been five Olympics football medallists from Africa with Nigeria winning gold, silver and bronze, Cameroon gold and Ghana bronze.