(CNN) -- Turkey produced one of the great comeback in European Championship history as Nihat Kahveci scored twice in a dramatic final four minutes to beat the Czech Republic 3-2 in Geneva and seal a quarterfinal showdown against Croatia.
Turkish players mob Nihat Kahveci after his two late goals secured them a stunning quarterfinal place.
The Czechs looked home and dry in the 61st minute when Jaroslav Plasil added to Jan Koller's first-half opener to put his team 2-0 ahead.
But in an amazing end to the winner-takes-all match, Arda Turan halved the deficit in the 75th minute before Nihat came to the party.
The Turkey captain drew the sides level in the 86th minute when he took advantage of a terrible error by Czech goalkeeper Petr Cech to poke home into an empty net.
And the Villarreal striker sparked delirium among the Turkish fans when he curled home an unstoppable winner with just two minutes of the match remaining.
There was still time for Turkey goalkeeper Volkan Demirel to be sent off for an off-the-ball incident involving Koller, but Turkey held on to record their first win over the Czechs in 12 attempts.
Group B winners Croatia now lie in wait for the Turks in Vienna on Friday.
A penalty shoot-out loomed if the match had ended as a draw after 90 minutes but it looked long odds against that prospect the way Turkey played in the first half.
The more experienced Czechs, semifinalists at the Euros four years ago, were by far the better side and created more than the single goal they scored.
Koller, back in the starting line-up after being on the bench for the 3-1 defeat by Portugal, was at the hub of most of his team's attacks and he headed Marek Jankulovski's free-kick over the bar when well positioned in the 10th minute.
Marek Matejovsky, who was carried off on a stretcher in the 37th minute, then drew a decent save out of Volkan while Servet Cetin made a great last-gasp clearance to prevent Koller scoring a simple tap-in.
The ever-dangerous Libor Sionko then fired just over the bar in the 25th minute as the nervous Turks continued to relinquish possession.
The goal the Czechs deserved came nine minutes later. Juventus full-back Zdenek Grygera galloped down the right and crossed for Koller to power home a trademark header in emphatic style from inside the area.
That was his 55th international goal and the Nuremberg striker, who will now quit international football, almost made it 2-0 when he nodded over another Jankulovski set-piece.
Turkey came out with more purpose in the second-half and Nihat volleyed over acrobatically two minutes in while Tuncay Sanli deflected a free-kick straight at Cech.
The Czechs suddenly looked tentative but Plasil settled any nerves with their second just after the hour mark. Moments earlier, Koller had sidefooted wastefully wide with just Volkan to beat but Osasuna midfielder Plasil did much better when he got on the end of Sionko's right-wing cross to prod home at the far post.
The goal initially took the wind out of Turkey's sails and midfielder Jan Polak almost made it 3-0 when he sidefooted Sionko's cross against the post.
But it was not all over. Arda set up a tense final 15 minutes when he slid home a low finish past Cech after pouncing on a Hamit Altintop center.
And after Servet somehow headed wide from close range in the 81st minute, Cech spilled a comfortable deep cross from the right, allowing Nihat to force home the equalizer into an empty net.
Worse was to come for Cech when barely a minute later, Nihat made the most of some dreadful defending to latch on to a through-ball and curl home a superb finish off the crossbar.
In the final few seconds, Volkan saw red for shoving Koller, resulting in Middlesbrough striker Tuncay Sanli going in goal for the final two minutes, but Turkey held on for a dramatic and famous victory.
Turkish coach Fatih Terim, who may well earn an even higher title than his present nickname 'The Emperor', had a clear message for the Turkish people.
"I send a message to my country and I say to the people 'get on the streets, celebrate this victory, profit from this moment. I said after beating the Swiss that people would remember us. I say that again now after this victory," he added.
Czech captain Tomas Ujfalusi was left as stunned as his shellshocked team-mates after their stunning late collapse.
"We led 2-0 and should have controlled things from there," said the former Fiorentina defender. "But we completely messed up the end of the match. We went onto the back foot after their first goal and all we can say is we are distraught."