Lewis Hamilton's championship lead was cut to five points by McLaren team-mate Fernando Alonso after the Englishman suffered a late puncture in Turkey.
Hamilton was on course for third when his tyre shredded
Hamilton was on course for third place behind the Ferraris of Felipe Massa and Kimi Raikkonen when his right-front tyre fell apart with 15 laps to go.
The drama enabled Alonso to slip by into third place and left Hamilton in fifth behind BMW's Nick Heidfeld.
His car damaged by the puncture, Hamilton was not able to fight back.
The 22-year-old had been forced to trail back to the pits for the last third of the lap at Istanbul Park, and the flailing tyre damaged some of the aerodynamic parts at the front of his car.
That meant he was much slower than before the problem, and Heidfeld was able to pull away, leaving the McLaren driver to concentrate on staying ahead of Renault's Heikki Kovalainen.
Hamilton said: "It was just a little bit of a problem. You always have setbacks. I'm still leading by five points. It is not over."
Until the late puncture, Hamilton had had an uneventful race, with the Ferraris just too fast for him to challenge at the front.
The red cars were never more than a handful of seconds ahead of Hamilton, but they had enough pace to ensure he was never in the fight for the lead.
Massa led away from pole position at the start as Hamilton, lacking grip on the slippery side of the track, lost second place to Raikkonen.
Alonso, directly behind his team-mate in fourth place on the grid, fared even worse, and dropped down to sixth behind both BMW Saubers, which he had to follow until they made their first pit stops.
The Spaniard made a couple of abortive attempts to pass Heidfeld once the German's team-mate Robert Kubica made his first pit stop early on lap 12, but had to wait until Heidfeld's stop on lap 17 to assume fourth place.
Massa was able to control the race from the start
The world champion stopped only a lap later than Heidfeld, but it was enough for the McLaren to leapfrog the BMW.
Once Hamilton made his stop two laps later, the Englishman was about 14 seconds ahead of his team-mate.
And while Alonso was able to hold the gap, and occasionally close it, he was not able to make a significant impression on Hamilton until the late-race drama.
Alonso said: "To be overtaken by two cars and find yourself sixth going into the first corner is not great.
"You just have to wait for the miracle and it only happened with Hamilton.
"If someone had told me on lap two that I would have been on the podium it would not have been easy to believe.
"The final result is the best thing of the weekend... I will not remember this Grand Prix all my life but, anyway, it has been quite good."
Ahead of the McLarens, the Ferraris were fighting a private battle.
Turkey is where I started winning races and fighting with the front-runners - having the second win consecutive win here is fantastic
Raikkonen closely followed Massa for the first stint of the race, giving the impression that he was the faster of the two.
But the Finn stopped a lap earlier than Massa, who emerged from the pit stops with a two-second lead.
He held the margin and looked in complete control until a few laps before his second and final pit stop when he was held up in traffic and Raikkonen closed right up on to his tail.
But Massa kept his cool and, again stopping a lap later than Raikkonen, held the lead to the end.
Massa's win meant he moved one point ahead of Raikkonen in the championship, but still 15 points adrift of Hamilton.
The Brazilian was delighted to win in Turkey for the second successive year, after taking his maiden win at the track in 2006.
"To win a second race in a row here, starting from pole, is amazing," said the Brazilian. "I love the place.
"Turkey is where my career made a switch and I started winning races and fighting with the front-runners.
"Having the second win consecutive win here is fantastic. It is difficult to find the right words."
Raikkonen was left to rue the mistake in qualifying that had left him third on the grid.
"In these days it's hard to get past - the race was decided in qualifying," he said.
"When two team-mates are fighting, it's whoever is first that is usually going to stay there.
"The car was very good but there is nothing more I could have done."
Kovalainen was not able to catch Hamilton's McLaren and the Finn finished sixth after a strong race in the Renault, with Williams's Nico Rosberg and BMW Sauber's Robert Kubica taking the final points positions.
Turkish Grand Prix result after 58 laps at 3.34-mile Istanbul Park track:
1 Felipe Massa (Brz) Ferrari 1hr 26mins 42.161secs
2 Kimi Raikkonen (Fin) Ferrari 1:26:44.436
3 Fernando Alonso (Spa) McLaren-Mercedes 1:27:08.342
4 Nick Heidfeld (Ger) BMW Sauber 1:27:21.835
5 Lewis Hamilton (GB) McLaren-Mercedes 1:27:27.216
6 Heikki Kovalainen (Fin) Renault 1:27:28.330
7 Nico Rosberg (Ger) Williams-Toyota 1:27:37.939
8 Robert Kubica (Pol) BMW Sauber 1:27:38.868
9 Giancarlo Fisichella (Ita) Renault 1:27:41.652
10 David Coulthard (GB) Red Bull-Renault 1:27:53.569
11 Alexander Wurz (Aut) Williams-Toyota 1:28:01.761
12 Ralf Schumacher (Ger) Toyota at one lap
13 Jenson Button (GB) Honda at one lap
14 Anthony Davidson (GB) Super Aguri-Honda at one lap
15 Vitantonio Liuzzi (Ita) Toro Rosso-Ferrari at one lap
16 Jarno Trulli (Ita) Toyota at one lap
17 Rubens Barrichello (Brz) Honda at one lap
18 Takuma Sato (Jpn) Super Aguri-Honda at one lap
19 Sebastian Vettel (Ger) Toro Rosso-Ferrari at one lap
20 Sakon Yamamoto (Jpn) Spyker-Ferrari at two laps
R Adrian Sutil (Ger) Spyker-Ferrari 53 laps completed
R Mark Webber (Aus) Red Bull-Renault nine laps completed
Key: R = retired