Ruiz struck right at the end of the opening period in the match in Recife 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.
Italy's hopes of joining Costa Rica depend on them getting a point from the match with the Uruguayans.
Italy coach Cesare Prandelli said he felt sorry for England but that was as far as it went.
"I'm really sorry for them, but also for us!" said Prandelli.
"Because we also wanted to win. I don't have any messages for England. We have our own issues to solve."
For the Costa Ricans it is only the second time they 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 were a shadow of the side that beat England 2-1 last Saturday as they showed little sign of urgency throughout with misplaced passes and lackadaisical defending.
Italy had little to offer in the opening half save for a sublime Andrea Pirlo chip over the top of the Costa Rican defence which found Mario Balotelli in space on the half hour only for the AC Milan striker to loft his effort off target.
Balotelli, who scored the winner against England last Saturday, pounced on a deft header from Pirlo a minute later but Keylor Navas blocked the striker's fierce drive from the edge of the area.
As Italy wavered, Costa Rica kept the Italian defence on their toes. Arsenal's Joel Campbell looked to have won a cast iron penalty in the 43rd minute as he pounced on a mistake by Giorgio Chiellini and broke into the Italian penalty area where he was barged over by the Juventus defender.
Chilean referee Enrique Osses, however, waved away furious appeals by the Costa Ricans with Pinto going berserk on the touchline.
Barely two minutes later, Pinto was jumping for joy as his side got the goal they deserved.
Gianluigi Buffon, who sat out the England win due to an ankle knock, 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.
Prandelli shook things up immediataly, introducing forward Antonio Cassano for Thiago Motta for the second-half.
But although Italy started the second half in brighter fashion, a Pirlo free kick hardly caused Navas any problems in the 53rd minute.
While the Italians tried to conjure up chances which came to nothing Pinto replaced Campbell with Marcos Urena on 74 minutes and his fresh legs almost made an impact.
Christian Gamboa did well to dispossess Pirlo outside the area and fed Ruiz on the right, but the Italian defence dealt with his delivery to Urena.
Costa Rica threatened again when Urena ran on to a long ball lofted from midfield, only for Chiellini to this time block the striker's shot on the edge of the area.
Italy's last chance was a drive from Cerci that smacked off the face of Giancarlo Gonzalez, but his effort -- much like Italy's game all round -- was offside.