Having never scored before in the competition, the world's 132-ranked nation produced one of the biggest shocks in its history.
El Fardou Ben Mohamed put the AFCON debutants ahead before Ahmed Mogni added a second.
Reduced to ten men, Ghana threatened to deny the fairytale when goals from Richmond Boakye and Alexander Djiku levelled things up.
But Mogni netted with five minutes to go, sending the Black Stars packing after failing to win any of their Group C matches - the first time that has happened in their 22 appearances at AFCON.
Comoros, meanwhile, entertain slim hopes of progressing as the best third-place side, behind Morocco and Gabon - who go through automatically.
The result marks a dark day in Ghana's football history, capturing the demise of a nation who once flew the flag for Africa, reaching the 2010 World Cup quarter-finals.
However, their loss is Arsenal's gain, as key midfielder Thomas Partey returns to the Gunners earlier than expected.
Arsenal's recent Premier League clash with Tottenham was postponed with the Gunners short of players, particularly in midfield.