With the score tied 1-1, it seemed Cote d'Ivoire had done enough to book their berth in the knockout stage against a Greece side that had failed to score in their opening two matches.
But Samaras won a debatable penalty in the 90+3 minute and then himself slotted the spot kick that broke Ivory Coast hearts.
FINAL GROUP C STANDINGS
Colombia Played 3, Won 3, Goals for 9, Goals against 2, Points 9
Greece Played 3, Won 1, Lost 1, Drawn 1, GF 2, GA 4, Points 4
Ivory Coast Played 3, Won 1, Lost 2, GF 4, GA 5, Points 3
Japan Played 3, Drawn 1, Lost 2, GF 2, GA 6, Points 1
Greece will join Colombia, who topped the Group after their 4-1 win over Japan.
The European side will take on surprise package Costa Rica while Colombia will lock horns against Uruguay.
Greece started the better of the teams. Cote d'Ivoire, though, settled quickly and started having more possession of the ball.
Both teams were poor in the final third with the African nation, especially, guilty of throwing it all away with the final pass.
Ivory Coast were just seconds away from a Round 2 berth when Greece scored
Gervinho, Didier Drogba and Yaya Toure posed the greatest threat to the Greek goal.
Drogba worked hard but didn't get good enough service from his teammates.
After a cagey start, the game started opening up in the second part of the half.
Jose Holebas could so easily have given his side the lead but his effort cannoned of the crossbar in the 33rd minute.
Andreas Samaris gave his side the lead after a disastrous pass from Newcastle United midfielder Cheick Tiote that handed Greece the goal.
Ivory Coast attacked the Greece goal looking for the equaliser but again the final play let them down.
In the second half, Cote d'Ivoire continued to pressure the Greek defence and made constant inroads into the box.
With the African side going for equaliser, Greece attackers found ample space and played good counter attack.
Greece could have easily had two as midfielder Lazaros Christodoulopoulos drove at the Ivorian defence, before feigning a shot and opening a brilliant scoring opportunity but sliced his effort narrowly wide.
For all their attacking play Ivory Coast found it hard to break the Greek defence and really test the substitute goalkeeper.
Greece created the better chances of the two and once again beat the Ivory Coast keeper from a Giorgis Karagounis' thunderbolt but for the second time in the match, struck the crossbar.
Swansea forward, Bony finally scored the goal that his team richly deserved.
Gervinho's beautiful cut-back found Bony, who first-timed his shot in past a diving Greek goalie.