Comoros players celebrate after scoring the opening goal during the Group C Africa Cup of Nations (CAN) 2021 football match between Ghana and Comoros at Stade Roumde Adjia in Garoua on January 18, 2022. AFP
The Black Stars had captain Andre Ayew sent off after 25 minutes and, after wiping out a two-goal deficit, lost when Comoros' Ahmed Mogni scored his second goal five minutes from time.
Morocco and Gabon drew 2-2 in Yaounde in the same group to retain first and second places respectively and qualify for the round of 16, which kicks off on Sunday.
Comoros, representing a tiny island nation off the south east coast of Africa, finished third and must wait until Thursday to know if they are among the best four third-placed teams, who get last 16 spots.
A disastrous night for Ghana started after just four minutes when Serbia-based El Fardou Ben Mohamed fired the first-time qualifiers in front.
Mogni, who plays for French third-tier club Annecy, added a second just past the hour only for 10-man Ghana to hit back through goals from Richmond Boakye and Alexander Djiku.
Mogni struck again when he pushed a low cross from Ben Djaloud past goalkeeper Joseph Wollacott to give the islanders a stunning triumph.
In Yaounde, Gabon led twice through Jim Allevinah and a Nayef Aguerd own-goal while Sofiane Boufal and Achraf Hakimi netted for Morocco.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)