A keenly-contested last-16 encounter in Recife ended 1-1, with Bryan Ruiz’s opener cancelled out by Sokratis Papastathopoulous in second-half stoppage-time.
An extra 30 minutes failed to deliver another goal, despite Costa Rica playing close to an hour at a numerical disadvantage following the dismissal of Oscar Duarte, and the contest was settled with a test of nerve from 12 yards out.
It took 52 minutes for the deadlock to be broken in normal time, with Christian Bolanos cutting back to the edge of the box for Ruiz to sweep into the bottom corner.
Costa Rica, who had overcome Uruguay and Italy en route to the second round, found themselves in dreamland, but their night took a turn for the worse on 66 minutes as Duarte picked up a second yellow card for a clumsy challenge on Jose Holebas.
Jorge Luis Pinto’s men were always holding on from that point and they fell agonisingly short inside 90 minutes as Papastathopoulous found himself in the right place to bundle home in the dying seconds as Keylor Navas parried an effort from substitute Theofanis Gekas.
Greece had the better of the chances to win the game inside the distance from there, most notably through Kostas Mitroglou, but spot-kicks were to decide the outcome and Navas became a national hero as he saved from Gekas and Michael Umana stroked home the match-winner.
It was an exciting end to a scrappy match in which the only moment of note in the opening 20 minutes was a left-footed drive from the recalled Cristian Bolanos that flew just over.
Greece were enjoying the lion’s share of chances but were looking susceptible defensively at times, with skipper Giorgos Karagounis avoiding a penalty more through luck than judgement when catching Joel Campbell on the edge of the box.
It looked like a penalty on first glance but referee Ben Williams was right adjudge the foul to have taken place just outside the area, with the resulting free-kick coming to nothing.
Veteran Karagounis tried his luck from distance when Greece returned to the attack – a chance Navas dealt with easily, before having to be at his best to keep the scores level in the 37th minute.
Meeting a fine left-wing Jose Holebas cross, Salpingidis looked certain to score from close range only for the Costa Rica goalkeeper to stop the goal-bound strike with his right leg.
Duarte joined Andreas Samaris in the referee’s notebook just before the half-time whistle went, with the locals letting their displeasure at the lack of quality known.
Los Ticos failed to conjure a single shot on target in the opening period but changed that just seven minutes after the restart, breaking the deadlock in the process.
Bolanos pulled the ball back from the left into the path of Ruiz, who was afforded too much time to coolly roll home a first-time left-footed strike, which trickled past Orestis Karnezis.
It was a fine placed effort and Costa Rica should have had the chance to double their advantage moments later when Vasilis Torosidis turned away a cross with his hand.
Substitute Oscar Granado was booked for his remonstrations as tensions rose, with Costa Rica reduced to 10 men in the 66th minute when Duarte picked up a needless second booking for tripping Holebas.
Georgios Samaras flashed a header wide almost immediately before Navas flapped at his looped ball as Greece upped the ante.
Substitute Gekas turned wide, Kostas Manolas headed over and Karagounis wasted a free-kick as the game looked to have got away from them, only for Papastathopoulos to net a stoppage-time leveller.
With the ball fired into the box, Gekas saw a snapshot parried by Navas and the ball fell kindly for the centre-back to fire home.
It was the first time the Costa Rica goalkeeper had been beaten from open play in Brazil and he had to be at his best to stop Greece doing so again moments later, tipping over a powerful header from substitute Mitroglou.
The Fulham striker failed to get a telling touch to beat Navas again as extra-time began, before an unsighted Gekas directed wide and Konstantinos Katsouranis had a close-range effort blocked.
Randall Brenes came close for Costa Rica at the start of the second period of extra time in which Lazaros Christodoulopoulos stung the palms of Navas, who then denied Mitroglou at the death as the match went to penalties.
Greece coach Santos was sent to the stands before the spot-kicks began, with every one finding the net until Navas denied Gekas with Greece’s fourth of the night.
It gave Umana the opportunity to secure victory, which he duly did by firing the ball into the top right-hand corner.