Moise Adilehou gave Benin a shock lead after 53 minutes through a right-foot shot from the center of the box.
Yousef Al Nusairi equalized the scoring in the 75th minute after he fired a left-foot shot from the center of the box past Squirrels' keeper Fabien Farnolle
Ajax’s midfielder Hakim Ziyech's missed a penalty in the last minute of the second half which was enough for his side to qualify for the last Eight.
Squirrels will face either Senegal or Uganda in the quarter-finals of the tournament.
Morocco began the game so fiercely as early as after only six minutes when Yousef Al Nusairi fired a right-foot shot from the center of the box kept away by Squirrels' keeper Fabien Farnolle.
In the 28th minute, Benin's goalkeeper was brought into action again as his save denied Ajax’s midfielder Hakim Ziyech's left-foot shot.
Seven minutes later, Ziyech came close to putting his side ahead after he fired a left-foot shot from a direct free kick missed to the right.
Eight minutes after the beginning of the second half, Squirrels' defender Moise Adilehou opened the scoring to put his side ahead. Atlas Lions' forward Yousef Al Nusairi then equalized the scoring in the 75th minute of the game.
In the first half of extra time, Squirrels' defender Khaled Adenon received his second yellow card and was sent off for the closing stages.
Benin's goalkeeper was brought into action again as his save denied Sofiane Boufal's right-foot shot.
[gallery size="large" columns="1" ids="62788,62787,62786,62785,62784,62783,62781,62780,62779,62778,62777,62775,62776,62774,62773"]