Victory would have been enough for the Black Stars to progress as one of the best third-placed teams but a double from Ahmed Mogni gave the Comoros its first Africa Cup of Nations win in a Group C encounter that saw captain Andre Ayew sent off for the four-time champion Black Stars.
Comoros took a shock lead in the fourth minute as a quick break was finished off by El Fardou Ben Nabouhane with a confident strike into the bottom-right corner.
Ghana's problems deepened when Ayew was shown red as it pressed for an equaliser, the skipper deemed by VAR to have fouled goalkeeper Salim Ben Boina in an effort to prod home a rebound from Kamaldeen Sulemana's shot.
And the advantage of the extra man at the Comoros's disposal eventually told just after the hour as haphazard goalkeeping from Jojo Wollacott presented Mogni with the chance to double the advantage courtesy of an assured finish.
Richmond Boakye provided an instant response when he steered home a header from a corner and the turnaround looked to be on when Alexander Djiku tapped in a flick-on as the Comoros defence failed to deal with the same set-piece with 13 minutes remaining.
A decisive fifth goal did arrive, but it was Mogni who had the final say as he was presented with a simple finish after excellent work down the right from Bendjaloud Youssouf to keep the minnow's hopes of qualification for the knockouts alive and condemn Ghana to an embarrassing exit.