Samaras stroked home a controversial 93rd minute penalty after he was judged to have been tripped in the box by Giovanni Sio as the Greeks poured forward in search of a winner.
Replays showed that Samaras caught his foot on Sio’s calf, tripped and fell, but Ecuadorian referee Carlos Vera pointed to the spot and Samaras cooly converted the kick.
“We went for the win in the last 20 minutes,” Samaras said.
“I thought we controlled the game. They didn’t have many chances. It means a lot for the team and I hope we gave a lot of joy to the Greeks back home.”
Defeat was heart-breaking for the Ivorians, who had fought their way back from a goal down and were just seconds away from a draw that would have taken them through.
“The end result is cruel even if the Greeks deserved this victory,” Ivory Coast Sabri Lamouchi said. “It’s very tough, it’s very hard. It’s very disappointing and frustrating for me. The whole team put in a lot of effort.”
Ivory Coast players wore black armbands for the match following the death last week of Ibrahim Toure, the younger brother of two of their players, Kolo and Yaya Toure.
Greece’s win left them second in the group on four points, one ahead of Ivory Coast and three clear of Japan. Colombia topped the group with a perfect nine points.
Having failed to get past the group stage at their two previous appearances at the World Cup, Greece will face Costa Rica in Recife on Sunday in the last 16.
For a long time it looked like it might not be Greece’s day. They hit the Ivorian crossbar twice and the post once.
The match started dismally for them when they were forced to make two substitutions within the first 25 minutes.
Midfielder Panagiotis Kone limped off after 12, to be replaced by Samaris, and then goalkeeper Orestis Karnezis retired with a back injury.
But despite that, Greece almost took the lead after half an hour, defender Jose Holebas crashing a piledriver off the Ivorian crossbar.
Three minutes before halftime they went ahead, Andreas Samaris pouncing on a mistake by Cheick Ismael Tiote and exchanging a quick one-two with Samaras before firing a low shot past Boubacar Barry.
The Ivorians kept plugging away after the break and equalized on 74 minutes, substitute striker Wilfried Bony connecting with a low cross from Gervinho.
That would have been enough to take the Africans through until Samaras’s late strike turned the tie on its head once more and sent the Ivorians home at the group stage for the third consecutive World Cup.
(Additional reporting by Karolos Grohmann,; Editing by Nigel Hunt)