The seven times winners were on the back foot for much of the last eight game against their north African rivals but grabbed the winner from an 87th minute corner.
Morocco failed to clear the bouncing ball and substitute Kahraba hooked it home from close range to book a semi-final against Burkina Faso on Wednesday.
Ghana meet Cameroon in the other semi-final in Franceville on Thursday.
(Reporting by Mark Gleeson; editing by Ken Ferris)
