Morocco star Hakim Ziyech's 90th-minute penalty miss cost his side dearly as Benin went on to win 4-1 on penalties and reach the quarter-finals of the African Cup of Nations for the first time.
Youssef En-Nesyri's equaliser 14 minutes from time got Morocco back into the game after Moise Adilehou's shock opener and it seemed like they would go through when Benin skipper Stephane Sessegnon felled Achraf Hakimi in the box.
Ziyech sent the goalkeeper the wrong way but saw his effort come agonisingly hit the outside of the post.
Benin played 23 minutes of extra time down to ten men after Khaled Adenon was dismissed for apparently shoving the referee, a second bookable offence.
He left the pitch very reluctantly before engaging in an argument with the Moroccan bench and it remains to be seen if he will play again in the tournament.
The underdogs looked to have been looking to get to penalties from the first minute and their accomplished kicks suggested as much. In contrast Morocco appeared nervy in the shoot-out with Sofiane Boufal blazing over the bar and Youssef En-Nesyri seeing his kick saved.