Ruiz struck right at the end of the opening period after the Costa Ricans had a valid appeal for a penalty waved away by the referee.
Costa Rica’s victory saw them move onto six points in Group D and means that pointless England’s slim hopes of getting second spot were extinguished as Uruguay and Italy, both on three points, play each other in their final game.
It will be the second time Costa Rica have reached the last 16, the previous occasion being in the 1990 finals.
Italy’s poor performance was encapsulated by the fact they had not gone goalless in a World Cup finals match since the 1998 edition in France.
Italy showed little sign of urgency throughout with misplaced passes and lackadaisical defending.
However, their midfield wizard Andrea Pirlo produced one sublime pass chipped over the top of the Costa Rican defence in the 31st minute which found Mario Balotelli.
The AC Milan striker, though, lofted the ball over the Costa Rican ‘keeper but the ball went wide of the far post.
It was Costa Rica who broke the deadlock with an excellent goal.
Gianluigi Buffon failed to come for a Junior Diaz cross to the far post and Ruiz produced a superb header which beat the 2006 World Cup winning goalkeeper and bounced over the line after hitting the underside of the bar.