Guinea captain Pascal Feindouno scored twice, only to be sent off as the Syli Nationale held on to beat Morocco.
Bangoura scored Guinea's second
Feindouno's curling free-kick gave Guinea a first-half lead, and on 59 minutes he set up Ismael Bangoura who scored with a left-footed shot.
Seconds later Hicham Aboucherouane's superb strike pulled a goal back for Morocco, before Feindouno's penalty strike took a pulsating game to 3-1.
He was then red-carded, with Abdeslem Ouaddou heading in Morocco's second.
Feindouno's sending-off could cost him at least a two-match suspension.
The result of this highly-charged encounter gives Guinea a strong chance of reaching the quarter-finals and leaves Morocco with plenty to do.
Guinea made three changes to the side that lost their opener to hosts Ghana and winger Fode Mansare made a real impact, his lively runs troubling the Morocco defence from the start.
The tournament continued to deliver superb goals, and Feindouno won the free-kick that gave Guinea the early lead.
His placement was superb from a tight angle down the left, curling the ball over the wall and to the near post, with Morocco goalkeeper Khalid Fouhami rooted to the spot.
But midway through the first half, Morocco striker Youssef Hadji had Kemoko Camara diving to his right to stop his shot from 20 yards.
Mansare came close 10 minutes before the break, with his free-kick tipped over the bar, though referee Jerome Damon awarded a goal kick.
Three minutes after the interval Hadji's first-time effort from outside the box was pushed over the bar.
Guinea's second came when Feindouno laid the ball through to Bangoura, who darted into the box and finished well.
Morocco pulled one back almost immediately, with substitute Aboucherouane's screamer flying into the far corner.
The frenetic pace continued, and Souleymane Youla was pulled down just inside the penalty area.
Feindouno slotted the spot-kick home, but three minutes later he was red-carded for kicking El-Armine Erbate in an off-the-ball incident.
It was the first red card of the 2008 tournament.
The remaining minutes saw Morocco doing all the attacking, and Ouaddou's header in the last minute set up a tense climax.
The match began in front of a small crowd, but numbers grew as the game progressed, as fans took their seats for the second game of the double-header, between Ghana and Namibia.
The much-maligned playing surface at the Ohene Djan Stadium played better than it had done for Sunday's opening game.
Guinea: Kemoko Camara, Ibrahima Sory Camara (Zayatte 81), Jabi, Bobo Balde, Kalabane, Mohammed Cisse, Mansare (Sacko 78), Sylla, Bangoura, Youla (Karamoko Cisse 77), Feindouno.
Subs Not Used: Diarso, Yattara, Habib Jean Balde, Alseni Camara, Diallo, Johnson, Correa, Bah, Soumah.
Sent Off: Feindouno (67).
Booked: Mohammed Cisse, Youla, Jabi, Sylla.
Goals: Feindouno 11, Bangoura 59, Feindouno 63 pen.
Morocco: Fouhami, Chretien, Ouaddou, Erbate, El Kaddouri, Kissi, Kharja (Aboucherouane 55), Safri, Hadji, Sektioui (Chamakh 62), Zerka (El-Moubarki 80).
Subs Not Used: Lamyaghri, Bagui, Mahdoufi, Alioui, Chahiri, El Karkouri, Kabous, Mokhtari, Alloudi.
Goals: Aboucherouane 60, Ouaddou 90. Ref: Damon Jerome (South Africa).