The Ticos` captain scored the goal that put Costa Rica ahead and also put away his penalty as the Central Americans kept their nerve to win the decider 5-3.
The two sides were 1-1 after regulation time with Sokratis Papastathopoulos cancelling out Ruiz`s goal in injury time to force extra time which also ended in deadlock.
Fanis Gekas missed Greece`s fourth penalty and Michael Umana converted Costa Rica`s fifth to seal the historic victory.
Costa Rica looked on target to pick off a new European scalp when in the 52nd minute Christian Bolanos found Ruiz on the edge of the penalty area and the skipper turned the ball into the net.
The shot by Ruiz, whose headed goal sank Italy in the key Group D clash, was not powerful. But Greek goalkeeper Orestis Karnezis and his defence seemed to stand still and watch it go by.
The goal brought Greece out of their shells and the pressure began to tell on the Costa Ricans. Oscar Duarte brought down Jose Holebas in the 62nd minute and his second yellow card meant his immediate expulsion.
Greece poured forward but still Costa Rica held on and believed the game was theirs when Papastathopoulos struck in the second minute of injury time.
Gekas fired in a low shot which Keylor Navas could not hold and the Borussia Dortmund defender hit in an easy rebound.