Match ends, Greece 2, Côte d'Ivoire 1.
Greece qualified for the last 16 of a World Cup for the first time with a dramatic victory against Ivory Coast.
Georgios Samaras converted a controversial injury-time penalty to seal the win after he was adjudged to have been fouled by Giovanni Sio.
Greece had taken a first-half lead when substitute Andreas Samaris scored after Cheick Tiote's defensive mistake.
Ivory Coast had looked like advancing as Wilfried Bony equalised from Gervinho's pass, before the late twist.
Soon after their elimination from the tournament was confirmed, Ivory Coast coach Sabri Lamouchi resigned.
Greece will face Costa Rica in the second round in Recife on Sunday, while the Ivorians have now gone out in the group phase in each of the last three World Cups.
They began the day second in the table and, with Colombia beating Japan 4-1 in the other Group C match, needed only a point to become the first African side to qualify for the second phase in this year's competition.
However, Greece, who offered little as an attacking threat in the second half, were given an opportunity to grab the winner when referee Christian Lescano pointed to the spot, despite Ivorian protests.
They were unhappy that Samaras, who kicked the turf, had fallen to the ground, but the official gave the decision and Samaras kept his composure to shoot past Ivory Coast goalkeeper Boubacar Barry for his first international goal since Euro 2012.
Greece started the day bottom of their group, and their hopes of qualifying suffered a further setback when they had to make two substitutions inside the first 24 minutes, including goalkeeper Orestis Karnezis with a back injury.
However, they created the best first-half opportunities with Samaras leading a quick attack and releasing Jose Holebas, whose shot from the edge of the penalty area rebounded off the crossbar.
Fernando Santos's Greece team went ahead with their first goal of the tournament and only their third in three World Cups.
Newcastle midfielder Tiote carelessly lost the ball to Samaris, who played a one-two with Samaras before lifting the ball over Ivory Coast goalkeeper Barry.
Despite the African side seeing more of the possession after the break, Karagounis almost made it 2-0 with a long-range effort that hit the crossbar.
But Ivory Coast, who had seen Salomon Kalou and Wilfried Bony shoot wastefully wide earlier in the second half, deservedly equalised with a quick counter-attack as ex-Arsenal forward Gervinho set up Bony.
The Swansea striker, who scored in their 2-1 win against Japan on Sunday, calmly finished past substitute goalkeeper Panagiotis Glykos.
That goal sparked wild Ivory Coast celebrations, but their joy turned to despair with Samaras's 93rd-minute penalty.
Ivory Coast coach Sabri Lamouchi: "My contract comes to an end at this World Cup and there will be no epilogue. It is logical as we did not do well at last year's Africa Cup of Nations or at the World Cup finals.
"The Ivory Coast is a great football nation. And this was a cruel game. After so much hard work and so much sacrifice, all of us and everyone in the Ivory Coast is very sad."
Greece coach Fernando Santos: "We found balance tonight. We are not the worst team when we lose or the best when we win.
"To everyone in Greece I say, 'Go out into the street and celebrate.'"
Greece captain Giorgos Karagounis: "We came here to advance from the group stage. We've never done it before, and we did in a great way.
"The goal should have come earlier. So God helped us in the end and we all thank him. We prevailed against the odds. We had passion and we had fight."
- 1KarnezisSubstituted forGlykosat 24'minutes
- 10KaragounisSubstituted forGekasat 78'minutes
- 8KoneSubstituted forSamarisat 12'minutes
- 20Gonzaroua DieBooked at 70mins
- 4K Touré
- 8KalouBooked at 62mins
- 9TiotéSubstituted forBonyat 61'minutes
- 11DrogbaBooked at 37minsSubstituted forDiomandeat 78'minutes
- 19Y Touré
- 10KouassiSubstituted forSioat 83'minutes
- 13Ya Konan
- Carlos Vera
- Shots on Target
Second Half ends, Greece 2, Côte d'Ivoire 1.
Attempt missed. Kolo Touré (Côte d'Ivoire) right footed shot from more than 35 yards misses to the left. Assisted by Yaya Touré.
Goal! Greece 2, Côte d'Ivoire 1. Georgios Samaras (Greece) converts the penalty with a right footed shot to the bottom right corner.
Penalty conceded by Giovanni Sio (Côte d'Ivoire) after a foul in the penalty area.
Penalty Greece. Georgios Samaras draws a foul in the penalty area.
Foul by Serge Aurier (Côte d'Ivoire).
Giannis Maniatis (Greece) wins a free kick in the defensive half.
Attempt saved. Yaya Touré (Côte d'Ivoire) right footed shot from a difficult angle on the right is saved in the bottom right corner.
Hand ball by Salomon Kalou (Côte d'Ivoire).
Foul by Giovanni Sio (Côte d'Ivoire).
Andreas Samaris (Greece) wins a free kick in the defensive half.
Offside, Côte d'Ivoire. Serey Die tries a through ball, but Giovanni Sio is caught offside.
Giovanni Sio (Côte d'Ivoire) wins a free kick in the defensive half.
Foul by Vasilis Torosidis (Greece).
Foul by Souleymane Bamba (Côte d'Ivoire).
Georgios Samaras (Greece) wins a free kick in the attacking half.
Attempt saved. Giovanni Sio (Côte d'Ivoire) left footed shot from the centre of the box is saved in the top centre of the goal. Assisted by Salomon Kalou with a headed pass.
Corner, Côte d'Ivoire. Conceded by Vasilis Torosidis.
Attempt blocked. Salomon Kalou (Côte d'Ivoire) right footed shot from the left side of the box is blocked. Assisted by Yaya Touré.