Greece took 10-man Costa Rica into extra time, but LosÂ TicosÂ won a dramatic penalty shoot-out and will play Holland.
Few expected either of these teams to reach the Last 16, but one of them will go through to face Holland in the quarter-finals. LosÂ TicosÂ already knocked out Italy and England, finishing ahead of Uruguay in the Group of Death, while Greece saw off the Ivory Coast with a last-gasp penalty.
OrestisÂ KarnezisÂ shook off a back problem to start in goal, but Bolognaâ€™sÂ PanagiotisKoneÂ was only fit for the bench.
ChristianÂ BolanosÂ blasted over andÂ GeorgiosÂ KaragounisÂ ran a big risk when clattering into Joel Campbell right on the outside edge of the box. That free kick was whipped across, but nobody got a clean enough header to it.
KaragounisÂ testedÂ KeylorÂ NavasÂ from distance, but the goalkeeper was forced into a splendid save as he rushed out to charge down aÂ DimitriosÂ SalpingidisÂ volley from point-blank range.
Oscar Duarte pulled back Bolognaâ€™sÂ LazarosÂ ChristodoulopoulosÂ for a booking towards the end of the first half, but the free kick was wasted.
Costa Rica knew they had to take the initiative and it paid off, as captain Bryan Ruiz horribly scuffed his shot from the edge of the box, but it worked in hisfavour, wrong-footing the goalkeeper to roll into the opposite corner. It was his second goal of the World Cup, as he also scored against Italy.
Roma full-back Vasilis Torosidis charged down aÂ BolanosÂ effort moments later, but replays showed he got away with a handling offence in the box that shouldâ€™ve been a penalty. He reached out an arm to redirect a cross.
Just as Costa Rica seemed to be in control, they went down to 10 men when Duarte completely mistimed his lunging tackle on Jose Cholevas for a second bookable offence.
Greece needed to step up and Samaras nodded wide from a free kick, while Theofanis Gekas couldnâ€™t get clean contact to a smart Cholevas cross. Karagounis and Konstantinos Manolas turned over from set plays, but Navas was only ever really threatened on 87 minutes when Mitrogluâ€™s first touch let him down on a Christodoulopoulos cross.
However, in stoppages Greece again showed their never-say-die attitude. Navas beat away a Gekas strike, but only into the path of ex-Genoa defender Sokratis Papasthatopoulos for his first ever international goal.
It was almost 2-1 for Greece, as Navas flew to flick a Mitroglu header out from under the crossbar.
Going into extra time, Gekas nodded wide from a deflected Torosidis cross and a desperate Giancarlo Gonzalez block stopped Katsouranisâ€™ shot from seven yards.
It was all Greece now, but Costa Rica threatened on the counter with a Randall Brenes pull-back intercepted by Katsouranis and Brenes going for goal himself.
Navas bravely rushed off his line to smother at the feet of Gekas and then beat away a Christodoulopoulos angled drive on a five against two counter-attack from Costa Ricaâ€™s corner. It was a huge opportunity wasted by the Bologna man.
Mitroglu thought he had won it at the 121stÂ minute, but Navas rushed off his line to deflect the volley with his thigh from point-blank range.
These two exhausted teams couldn't be separated, so this tie had to be decided on penalties. Bizarrely, Greece Coach Fernando Santos was sent to the stands before the shoot-out for dissent.
The first seven penalties were all converted successfully until Navas stuck up a hand to brilliantly save from Gekas. It proved decisive and Michael Umana kept his cool to fire in the winner.
Costa Rica 1-1 Greece (aet 5-3 on penalties)
Scorers: Ruiz 52 (C), Papasthatopoulos 91 (G)
Penalties:Â Borges (goal, C), Mitroglu (goal, G), Ruiz (goal, C), Christodoulopoulos (goal, G), Gonzalez (goal, C), Cholevas (goal, G), Campbell (goal, C), Gekas (saved, G), Umana (goal, C)
Costa Rica:Â Navas; Duarte, Gonzalez, Umana; Gamboa (Acosta 76), Ruiz, Borges, Tejeda (Cubero 65), Bolanos (Brenes 83), Diaz; Campbell
Greece:Â Karnezis; Torosidis, Manolas, Papasthatopoulos, Cholevas; Maniatis (Katsouranis 77), Karagounis; Salpingidis (Gekas 68), Samaris (Mitroglu 57), Christodoulopoulos; Samaras
Ref:Â Williams (AUS)
Sent off:Â Duarte 66 (C)