Moise Adilehou gave Benin the lead eight minutes into the second-half at the Al Salam Stadium in Cairo. But Youssef En-Nesyri drew Morocco level 15 minutes from time as Hervé Renard’s side grew stronger.
That the game went to extra-time came from a missed penalty in the dying seconds. Stephane Sessegnon felled Achraf Hakimi. But Hakim Ziyech sent his spot kick onto the post.
It was more misery for the Ajax striker who has failed to shine for his national team at the championships.
The 26-year-old was one of the Dutch side’s leading lights during their dazzling run to the Uefa Champions League semi-finals.
Following his miss, Morocco, who entered the tournament as Africa’s second highest ranked team, spurned another invitation to finish the job after Benin’s Khaled Adenon was sent off for his second bookable offence.
But the doughty 10 men held on despite the barrage to take the game to penalties where Morocco’s profligacy continued.
After Oussama Idrissi scored Morocco’s first, Sofiane Boufal and En-Nesyri fluffed their kicks.
With all of Benin’s three penalties successful, Seibou Mama thumped his shot to the right of the Morocco goalkeeper Yassine Bounou and peeled away to join his delirious teammates in their moment of history.