Paris, June 22: Ivan Perisic's last gasp winner gave Croatia a 2-1 win over Spain that condemned the defending European champions to a heavyweight last 16 clash against Italy while Germany claimed their place in the knockout rounds of Euro 2016.
Mario Gomez struck the only goal in a 1-0 victory over Northern Ireland in Paris to ensure Joachim Loew's men advance as Group C winners, with Poland through as runners-up following a 1-0 win over Ukraine.
Even Northern Ireland became one of the six latest nations through, stealing one of four spots for the best third placed finishers.
Spain must now beat Italy in a rematch of the 2012 final to remain in contention for a record third successive European Championship title after sliding to defeat against Croatia in Bordeaux.
Turkey beat Czech Republic 2-0 in the day's other Group D game. "It was not the desired route for us," said Spain coach Vicente Del Bosque.
"That is football, it seemed like we had the game controlled, but in football you can't take anything for granted. We will try to recover from this disappointment and prepare for Monday."
Tuesday's results also mean that Slovakia, Hungary and Northern Ireland are all guaranteed to reach the knockout stages.
Spain just needed to avoid defeat to secure top spot in Group D. Alvaro Morata grabbed a seventh minute goal that should have had Spain cruising towards a last-16 tie with a third-place team from Group B, E or F.
Despite the absence of injured Real Madrid star Luka Modric, Croatia fought back. Nikola Kalinic flicked home an equaliser on the stroke of half-time.
Spain captain Sergio Ramos then saw his second-half penalty saved by Danijel Subasic, and it cost his side dearly as Perisic struck a winner three minutes from time to fire Croatia through in first place.
With Italy guaranteed to finish top of Group E, Spain will have to beat them and then possibly Germany to reach the semi-finals. Hosts France or England could then stand in the way of a place in the July 10 final.
Turkey beat Czech Republic 2-0 through goals from Burak Yilmaz and Ozan Tufan, to keep alive their very slim hopes of reaching the next round.
They need Sweden and the Republic of Ireland to drop points against Belgium and Italy in Group E on Wednesday to advance as a best third-place team.
At Parc des Princes, Gomez was thrust into Germany's starting XI after Loew's side laboured to a 0-0 draw against Poland last week.
The on-loan Besiktas striker repaid his coach's faith with the only goal. Germany dominated, with Thomas Mueller, who set up Gomez's goal, twice firing against the woodwork in the first half.
Northern Ireland goalkeeper Michael McGovern pulled off several saves to limit the damage. Germany will now play Albania or Slovakia in Lille on Sunday.
"We played well and we were convincing but we didn't score nearly enough. That was really lacking today" said defender Mats Hummels.
"When we play against the really top teams we'll have to give it that little bit more." Coach Loew also bemoaned the missed opportunities. We created some very good chances, but also squandered a few.
"They had no chances, but we needed to have had more purpose and consistency in front of goal," Loew said.
Half-time substitute Jakub Blaszczykowski needed just nine minutes to fire Poland past the Ukraine in Marseille.
Blaszczykowski swept home a tidy finish following a cleverly-worked corner to leave Poland on seven points, level with Germany, but behind their neighbours on goal difference.
"We would have liked to have scored more goals, but when you see in the standings that we're only separated by goal difference from world champions Germany, you have to be happy," said goalkeeper Lukasz Fabianski.
"It's the first time in 30 years we've qualified from the group stage, we know we can go further and play better."
For Ukraine it was a third successive loss and the last match for coach Mykhaylo Fomenko, who announced earlier on Tuesday that he would leave his post following the tournament.