Ghana came from behind to earn a semi-final place with victory over Nigeria in a game full of drama.
Agogo was yellow-carded for removing his shirt after scoring
Nigeria took the lead on 34 minutes through a Yakubu penalty, but Michael Essien's glancing header put the Black Stars level on the stroke of half-time.
Ghana were reduced to 10 men on the hour, as captain John Mensah was sent off for a professional foul.
But Ghana continued to attack, and with eight minutes remaining, Junior Agogo's close-range finish gave them victory.
Ghana had the upper hand for most of the first half, which was a scrappy, physical affair.
The first clear chance fell to Nigeria on 11 minutes when winger Ikechukwu Uche went on a bustling run and set up Yakubu, who fired wide.
Nigeria defender Joseph Yobo almost put the ball in his own net three minutes later, as he cut out a Sulley Muntari cross.
Ghana striker Asamoah Gyan hit the post with a left-footer on 25 minutes, and Quincy Owusu-Abeyie's lively play persistently troubled Nigeria.
The Black Stars were still on top when they conceded the penalty, Eric Addo pulling Yakubu down.
The Everton striker stroked the spot-kick into the bottom-left corner, with Richard Kingson going the right way.
Ghana were down for the first time in the tournament, and faced a huge test of character.
The equaliser came with the last move of the first period, Owusu's cross was met with a glancing header by Essien.
The ball went in off the left post, and trickled along the goal line before going in.
The atmosphere at half-time was astonishing, with Ghana fans celebrating as if they had won the Nations Cup itself.
Nigeria came very close three minutes after the break, a 40-yard lob by Uche was pushed over the bar by a back-pedalling Kingson.
But Ghana remained in the ascendancy overall, with the crowd roaring on their every move.
The drama heightened when Mensah was sent off in the 60th minute for clipping down Osaze Odemwingie as he raced towards the penalty area.
Three Nigeria efforts were stopped from the resulting free-kick, but the Super Eagles failed to capitalise on their numerical advantage.
Ghana resisted the temptation to play for extra time and penalties, and the winner came on 82 minutes.
Muntari crossed inside the box to the unmarked Agogo, who finished from four yards out.
Nigeria were unable to respond, and Ghana beat them for only the second time at the Nations Cup, in what was a memorable match.
Ghana: Kingson, Sarpei, Mensah, Pantsil, Addo, Annan, Essien, Muntari, Quincy (Draman 74), Agogo, Gyan (Kingston 62).
Subs Not Used: Adjei, Afful, Alhassan, Asamoah, Asare, Ayew, Baffour, Barusso, Dauda, Kumordzi. Sent Off: Mensah (60).
Booked: Gyan, Agogo.
Goals: Essien 45, Agogo 83.
Nigeria: Ejide, Taiwo, Yobo, Shittu, Nwaneri, Obi (Obinna 85), Olofinjana, Etuhu (Eromoigbe 71), Uche, Odemwingie, Yakubu.
Subs Not Used: Aiyenugbu, Afolabi, Apam, Emeghara, Enyeama, Kanu, Makinwa, Martins, Okonkwo, Utaka.
Booked: Taiwo, Nwaneri, Obi.
Goals: Yakubu 35 pen.