(CNN) -- Italy and Spain reached the quarter finals of Euro 2012 -- but the World and European champions Spain were given a real fright before sealing their progress as group winners in Gdansk.
Goals from Antonio Cassano and substitute Mario Balotelli ensured Italy's safe passage and the holders could never be certain of joining them before substitute Jesus Navas struck two minutes from time.
His goal was enough to elevate Vicente del Bosque's side to the top of Group C, but until that point Spain knew that a Croatia winner would have sent the champions home.
Ultimately, it took a touch of late class from substitute Cesc Fabregas to open up the Croatia defence and allow Andres Iniesta to set up Navas for the crucial goal.
Croatia 0-1 Spain
Spain appeared remarkably relaxed, playing like a team that had already qualified, but in reality the qualification picture was on a paper-thin edge for most of the night.
Both sides knew that victory in this final group game would secure a quarter-final place, regardless of the outcome between Italy and Ireland in Poznan. The complexities of the qualification system meant that a 2-2 draw would have been enough to send both Spain and Croatia through -- but in truth that scoreline never looked a likely outcome.
The World and European champions rarely threatened and were indebted to goalkeeper Iker Casillas for keeping them level on the hour mark.
Luka Modric spun clear down the right and crossed to the far post, where Ivan Rakitic's firm header was brilliantly parried by the alert keeper.
It was a cross that Everton striker Nikica Jelavic would have craved and it was probably that realization that prompted Slaven Bilic to introduce the striker midway through the second half.
Within minutes, Jelavic just failed to climb high enough to connect with a cross from fellow substitute Ivan Perisic and Croatia were furious when Vedran Corluka appeared to have his shirt pulled in the penalty area, only for the offence to go unseen.
Stung by the emerging fear of an early exit, Spain coach del Bosque reverted to the tactics that had drawn widespread criticism in the opening group game with Italy, withdrawing striker Fernando Torres and bringing on winger Navas.
The conundrum that has shadowed Spain's presence in this tournament continued, with many more openings created but with no-one on the sharp end of the chances.
The tactic finally paid off though, as Fabregas chipped over three Croatia defenders who stood and appealed in vain for offside as Iniesta ran clear and rolled the ball into the path of a grateful Navas who could not miss.
Italy 2-0 Republic of Ireland
Substitute Mario Balotelli sealed Italy's progress with a stunning late volley as Ireland's misery at this tournament was compounded.
The night had started positively for Giovanni Trapattoni's Irish though. Not only did they manage to negotiate the opening four minutes of a match without conceding -- for the first time at this tournament -- they also posed a serious early threat to Italy.
The Italians weathered the early storm, though, and began to take control of the game as first Antonio Di Natale saw an angled effort scrambled off the line by Sean St Ledger, before Antonio Cassano's long-range effort was fumbled wide by keeper Shay Given.
From the resulting corner, Italy punished the rocking defence as Andrea Pirlo's centre was flicked on by Cassano whose header had already crossed the line before Damien Duff's belated clearance.
Cassano saw a shot blocked by Richard Dunne as Italy raised the pressure in the second half, but Ireland came close to an equalizer when Keith Andrews' deflected shot was pushed away by Gianluigi Buffon.
But when Andrews, already booked for a foul on Daniele De Rossi, picked up a second yellow for dissent late on, Ireland's tournament was effectively over.
There was still time for one final, painful twist, however, as Alessandro Diamante's corner was acrobatically volleyed home by Balotelli, despite the close attentions of John O'Shea.
Balotelli, left out of Cesare Prandelli's starting line-up for the first time at this tournament, might have had something to say about that decision, but his celebrations were deliberately and symbolically muted by Leonardo Bonucci clamping a hand across the striker's mouth.
Italy, though, might still have something to say at this tournament.