Brazil 2-2 Turkey
Turkey will play holders France in the Confederations Cup semi-finals after knocking
out world champions Brazil.
Gunes saw his side gain revenge for their World Cup semi-final defeat
The South Americans needed a win to go through but could only draw with the team they beat in last year's World Cup semis.
To make matters worse, they had Manchester United target Ronaldinho sent off in injury time at the end of the match.
He was given his marching orders after being shown a second yellow card for a tussle with Turkey goalkeeper Rustu Recber following Alex's late equaliser.
"We had our chance to qualify and we took it," said Turkey coach Senol Gunes. "We had wanted to play France in the final. Now it will have to be the semi-final."
Coach Carlos Alberto Parreira said: "There were two very different aspects to the game.
"In the first half, Brazil were far superior and had at least four chances to settle the match. But it was a totally different game in the second after Turkey scored."
Brazil took a deserved first-half lead through Adriano but were rocked by Gokdeniz Karadeniz's equaliser in the 53rd minute.
Turkey then took the lead nine minutes from time when substitute Okan Yilmaz found the net.
Substitute Alex fired in an equaliser in the third minute of stoppage time but it was not enough for Brazil.
Both sides finished with four points and the same goal difference in Group A but Senol Gunes's team went through on goals scored - four to Brazil's three.
Group B winners Cameroon, who drew 0-0 with the United States in Monday's other match, will play Colombia in the other semi-final, which also takes place on Thursday.
Brazil: Dida, Maurinho, Lucio, Juan, Gilberto (Kleber 75), Emerson, Kleberson, Ricardinho, Ilan (Gil 60), Ronaldinho (Alex 62), Adriano.
Turkey: Rustu Recber, Fatih Akyel, Bulent Korkmaz, Alpay Ozalan, Ibrahim Uzulmez, Ergun Penbe (Ibrahim Toraman 76), Volkan Arslan (Okan Yilmaz 35, Serkan Balci 87), Selcuk Sahin, Gokdeniz Karadeniz, Yildiray Basturk, Tuncay Sanli.
Referee: Markus Merk (Germany).