Lewis Hamilton took pole position from team-mate and title rival Nico Rosberg by a tiny fraction in a thrilling qualifying session in Singapore.
Hamilton was just 0.007 seconds quicker than Rosberg as Mercedes faced a threat from rivals Red Bull and Ferrari.
Red Bull's Daniel Ricciardo set the standard on the final run in the top 10 shoot-out but was pipped by 0.173secs.
Ricciardo was third from team-mate Sebastian Vettel and Ferrari's Fernando Alonso.
"Damn it," Rosberg said over the radio, when he realised he had been beaten by the narrowest of margins in probably the closest qualifying session of the year.
The German leads Hamilton by 22 points in the championship and a victory by either in the Singapore Grand Prix on Sunday would be a significant blow in their intense battle for the title.
But they will not have the race their own way, judging by the closeness of the opposition.
Hamilton and Rosberg were only sixth and seventh fastest after the first runs in final qualifying, beaten by both Williams cars, Ricciardo and both Ferraris.
Kimi Raikkonen, only 0.023secs slower than team-mate Alonso on the first runs, was taken out of the fight early when his engine hit trouble on his preparation lap for the final shoot-out.
The last few seconds were thrilling as Ricciardo set the pace with a lap of one minute 45.854 seconds, only to be beaten by Rosberg before Hamilton leapfrogged them both.
Vettel then leapt ahead of Alonso into fourth, knocking the Spaniard down to fifth even though the Ferrari driver had improved by more than 0.2secs over his first run. That, though, was enough to beat Massa by 0.093secs.
It was breathless stuff.
"That's probably the most exciting qualifying session I've had for a long time," said Hamilton. "Where there's a lot of people in the mix and you have to be spot on."
"I guess no-one was expecting to see how close everyone was. I saw the Ferraris very close and for it to end up as it did is great for our team.
"The last lap I locked up into turn one and lost quite a bit of time but managed to pull it back. I lost 0.15-0.2secs but I kept going and it got better and better on that lap. It ended up very close."
Rosberg said: "Seven thousandths, you know, it's nothing. I look back at the lap and I could have done it. But Lewis did a good job to get pole. Fair play."
Behind Massa, Raikkonen had to settle for seventh on probably his most competitive showing of a disappointing season, ahead of Williams's Valtteri Bottas, McLaren's Kevin Magnussen and Toro Rosso's Daniil Kvyat.
Magnussen's performance was especially impressive - he is the only driver who has never raced on this track before and he beat team-mate Jenson Button into 11th place.