Samaras, brought down by Giovanni Sio in the 91st minute, bravely stepped up to convert past a flailing Boubacar Barry before being mobbed by his team-mates.
It proved the last act of a thrilling Group C finale which Greece had led following Andreas Samaris’s strike near half-time, before Wilfried Bony equalised.
The Swansea City striker’s goal looked enough to take Ivory Coast through but Samaras’s penalty lifted Greece from bottom place to second, thanks also to Colombia’s 4-1 win over Japan.
Samaras’s goal brought a cruel end to the tournament for Ivory Coast’s Yaya and Kolo Toure, who were playing despite the death of their brother from cancer last week.
Veteran striker Didier Drogba took over captaincy duties from Yaya Toure as he made his first start of the World Cup.
And they combined for the Ivory Coast’s first dangerous moment but the Manchester City man’s pass into the box was too heavy for the 36-year-old Galatasary striker’s ageing legs to run on to.
Greece were forced into early changes when goalkeeper Orestis Karnezis came off with a back problem and midfielder Samaris replaced Panagiotis Kone, who went down holding his hamstring.
Ivory Coast were having trouble breaking down the compact Greeks and the Euro 2004 champions fired a warning when they quickly broke forward and Jose Holebas rattled the crossbar.
Georgios Karagounis, making his 139th apperance for the Greeks, then profited from indifferent defending when he blasted a low free-kick past the Ivory Coast wall but straight at Copa.
Greece’s opener, three minutes before half-time, stemmed from a mix-up when Samaras pounced on a loose pass by Cheick Tiote and fed Samaris who steadied himself and finished coolly.
Samaris was then on hand at the other end to deny Yaya Toure after he evaded two challenges and galloped into the Greek box, only to see his shot blocked by the midfielder.
Lazaros Christodoulopoulos had a shot deflected off-target early in the second half and Tiote then thumped one at replacement Greek goalkeeper Panagiotis Glyko.
A retreating Ivorian defence invited Christodoulopoulos to shoot once again but his shot from the edge of the area missed to the left.
The Greek defending was far more adroit and Konstantinos Manoloas slid in sharply to deny Salomon Kalou as he prepared to shoot.
Barry had to get everything behind a fierce drive from Dimitrios Salpingidis as Greece continued to threaten.
And another Greek break had the Ivorians in trouble, forcing Kalou into a last-ditch foul on Vasileios Torosidis at the expense of a yellow card.
Karagounis was inches from one of the goals of the tournament when his sensational long-range shot smashed off the crossbar, leaving the Fulham midfielder shaking his head.
With 16 minutes left, a Greek victory looked a formality but Bony, who came on for Tiote just after the hour-mark, had other ideas.
The Swansea City striker received a cute sideways pass in the box from Gervinho and he made no mistake with his first-time finish past Glyko.
The Greeks were going out and with time running short, Vasileios Torosidis tried his luck with a speculative shot from a tight angle which slammed off the near post.
Salpingidis’s cross ran across the face of goal as Greece pressed. And they finally got their reward when Sio, brought on just minutes earlier for Gervinho, upended Samaras.