Cenk Tosun scored a stoppage-time winner as Turkey beat the Czech Republic in a fiery final group game to secure a last-16 tie against Austria.
The Czechs needed to win Wednesday's final group game to avoid being eliminated, and they pushed for victory in the tense closing stages.
But they left gaps in defence and former Everton striker Tosun cut inside and drove a shot into the back of the net.
The Czech Republic's hopes of victory were not helped when they had Antonin Barak sent off midway through the first half for a second yellow card after catching Arda Guler with his studs up.
There were a total of 18 cards shown in or after the game, a new record for a European Championship match.
Initially, Turkey struggled to break down their opponents and finished the first half without a shot on target, but their passionate fans were sent wild six minutes after the break when captain Hakan Calhanoglu struck into the bottom corner.
That meant the Czech Republic needed to score twice, and they got back level when West Ham midfielder Tomas Soucek volleyed in from six yards.
The game was wide open after that as both sides pushed for victory, and it was Turkey who got it in the 94th minute to confirm their progress.
There were chaotic scenes right at the end as both sets of players clashed, resulting in the Czech Republic having another player sent off as Tomas Chory was shown a red card.
But the Turkey players were able to celebrate their dramatic win soon after and look forward to the knockout stages.
Both sets of fans had been enjoying the sunny weather in Hamburg in the build-up to the game but the heat may have also had an impact on a match that saw the most bookings in a Euros game.
Before the late sending off there had been a total of 17 yellows shown, with Barak's earlier red replacing the two yellows he had previously been given in data analysts Opta's card count for the match.
Eight of those bookings coming after the 80th minute as both sides pushed for a second goal.
Patrik Schick, the Czech Republic’s injured striker, was also one of those to be shown a yellow even though he did not get on the pitch.
The ill-discipline marred what had been a highly entertaining encounter, particularly after the Czech Republic had equalised to leave the tie delicately poised.
But once the final whistle went, Turkey's loud and passionate supporters were able to focus on another memorable win against the Czech Republic at a European Championship, having come from two goals down to beat them at the 2008 tournament - to also seal their progression from the group stage.
Source: BBC