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.
Their last-gasp victory 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.
"It means a lot for the team and I hope we gave a lot of joy to the Greeks back home. We are very happy and gave our answers on the pitch. I thought we controlled the game they didn't have many chances," Samaras said.
Ivory Coast coach Sabri Lamouchi said it would be his last match in charge of the team as his contract had now expired and would not be renewed.
"I'm deeply disappointed for the players. They deserved much better than what happened tonight. It was very cruel," he said.
The Greeks, who had failed to get past the group stage at their two previous appearances at the World Cup, will face Costa Rica in Recife on Sunday in the last 16.
Greece needed to win to stand any chance of going through and took the lead just before halftime, 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.
But the Ivorians equalised on 74 minutes, substitute striker Wilfried Bony stroking home after being set up by Gervinho.
The Greeks went back on to the attack and won with virtually the last kick of the match to send Ivory Coast home at the group stage for the third consecutive World Cup.