Substitute Winston Parks rammed in an 86th minute equaliser to earn Costa Rica a 1-1 World Cup group C draw with Turkey and ensure that Brazil went through to the second round.
A second-half goal from Emre Belozoglu looked to have earned Turkey victory but a goalmouth melee left the ball bouncing invitingly for striker Parks who smacked it joyously into the roof of the net from close range.
Costa Rica now have four points from two games, having beaten China 2-0 in their opening match, and they need a point against Brazil in their final game to reach the last 16.
"It is a bitter disappointment," said Turkish coach Senol Gunes. "We were playing to win but after the second goal some of our players got tired and Costa Rica began to play more offensively and made more chances.
"We are here at the World Cup after 48 years. We scored our first goal against Brazil and got our first point against Costa Rica. We are confident of a win against China and we will wait for the right result to go through."
Brazil have won both their matches, beating China 4-0 on Saturday night, and join Spain as the only two countries so far to have reached the last 16.
World Cup debutants China are now out of the 32-team tournament along with Saudi Arabia, Slovenia and Nigeria.
The late goal sparked a touchline confrontation between officials and players of both sides when Emre Belozoglu pushed over a Costa Rican official who he suspected of time-wasting. The Turkish scorer was booked.
Turkey had gone ahead after 56 minutes when midfielder Emre Belozoglu's first shot on the right side of the box was blocked by Costa Rican defender Gilberto Martinez but he managed to turn to find the net with his second effort.
BEST CHANCE
Both teams have only reached the World Cup finals once before. They created few clear-cut chances before the goal.
Costa Rican midfielder Walter Centeno had the best chance of the first half when he found himself free on the right side of the box in the 33rd minute but he struck his shot over the bar.
Referee Coffi Codjia, the first referee from the African state of Benin to control a World Cup match, showed four yellow cards before the break to Turkey's Emre Asik and Tugay Kerimoglu and Costa Rica's Gilberto Martinez and Carlos Castro.
The pace of the game appeared to pick up after the break. Turkey striker Hakan Sukur went close twice in the first three minutes of the half with a header and a shot.
Costa Rican forward Ronald Gomez also hit a fierce left-footed shot wide in the 51st minute as his side missed a series of good chances through over-elaboration in front of goal. Then came Parks's timely strike.