First, Andrea Pirlo's glorious ball over the top dropped perfectly for Balotelli, who controlled it with one touch and then lofted it over the on-rushing keeper Keylor Navas but it bounced well-wide and the former Manchester City striker held his head in his hands.
Two minutes later and Balotelli was in again, this time he went for power but too close to Navas, and the Costa Rica keeper was able to claim at the second attempt.
With half-time looming, Costa Rica were denied a blatant penalty.
Joel Campbell, the Arsenal striker on loan at Olympiakos, intercepted a pass, surged into the penalty box and was knocked over from behind by Giorgio Chiellini but Chilean referee Enrique Osses inexplicably waved 'play on'.
Costa Rica did not let that put them off their stride however and Junior Diaz' exceptional cross from the left saw Fulham striker Ruiz, leaving his marker Chiellini in no man's land, thump a far-post header in off the crossbar. It bounced a foot over the line but goal-line technology ensured there was not another travesty of justice.
Italy upped their game after the break, realising defeat would leave them vulnerable against Uruguay, with Parma striker Antonio Cassano coming on for defensive midfielder Thiago Motta.
Balotelli claimed a penalty of his own under challenge from Oscar Duarte, but it was not nearly so clear-cut as Costa Rica's the referee once again turned away.
Italy mounted a series of attacks but Navas was having a blinder in the Costa Rica goal, first tipping over Matteo Darmian's angled drive, and then turning aside Pirlo's free-kick after Cassano had hurled himself to the floor to earn it.