The Brazilian leapt to the top of the timesheets on his final run, finishing 0.087s ahead of team mate Valtteri Bottas to complete a Williams one-two - the team's first in qualifying since the 2003 German Grand Prix.
Championship leader Nico Rosberg was third fastest, but Mercedes team mate Lewis Hamilton failed to set a time in Q3 after a dramatic spin.
It was also a bad day for Red Bull's defending champion Sebastian Vettel, who was knocked out in Q2 and will therefore start Sunday's race from 12th.
Hamilton had headed the times in Q1 with 1m 09.514s on Pirelli's soft-compound tyres, with Toro Rosso's Daniil Kvyat a superb second after a 1m 09.678s on the supersofts.
Numerous drivers had times disallowed for failing to respect track limits between Turns 8 and 9, however, most notably Adrian Sutil, who would have got into Q2 had his lap of 1m 10.774s been permitted. Instead the Sauber driver ended up a frustrated 17th on 1m 10.825s - just four-thousandths of a second slower than the Lotus of Pastor Maldonado.
Esteban Gutierrez in the second Sauber was also out in Q1 after coming round in 1m 11.349s. Jules Bianchi looked a possible Q2 runner but was ultimately 19th for Marussia on 1m 11.412s ahead of Caterham's Kamui Kobayashi on 1m 11.673s, team mate Max Chilton on 1m 11.775s and Marcus Ericsson on 1m 12.560s in the second Caterham.
The big shock for the local fans in Q2 was Vettel's failure to progress into Q3. As Rosberg set the first sub-1m 09s lap of the weekend with 1m 08.974s, Sergio Perez was the first faller for Force India, with 1m 09.754s. Jenson Button didn't make it either, with 1m 09.780s for McLaren, while Vettel came up short with 1m 09.801s - little more than one-tenth of a second off Ferrari's Kimi Raikkonen, who scraped through in 10th.
In the other Red Bull, Daniel Ricciardo was also in the drop zone entering the final moments of Q2, but a late effort lifted him into ninth.
Maldonado's own late flyer, in contrast, ended in the gravel at Turn 5, leaving the Lotus driver 14th on 1m 09.939. Then came Jean-Eric Vergne for Toro Rosso on 1m 10.073s and Romain Grosjean on 1m 10.642s, the Lotus driver having a time disallowed.
The track temperature rose from 32 to 34 degrees Celsius for Q3, and straight away Bottas got in a tremendous banker lap of 1m 08.846s to top the times.
Rosberg quickly moved to second on 1m 08.944s (slower than his Q2 best of 1m 08.974s), but Hamilton had his time disallowed after running wide exiting Turn 8, having set overall bests in the first two sectors. Worse was to follow, as he locked up and spun at Turn 2 on his final run, leaving him without a time. He will start ninth as Force India's Nico Hulkenberg had his only timed lap of the session deleted, again for track limit violations.
Bottas had a big wobble in the middle sector on his own final effort and failed to improve, but Massa blasted round in 1m 08.759s to deny his team mate and end a six-year wait for his 16th career pole.
Rosberg thus had to be content with third place, his own lap having been spoiled when Hamilton spun directly in front of him. He shares the second row with Fernando Alonso, who took his Ferrari round in 1m 09.285s. Ricciardo rescued things for Red Bull with fifth on 1m 09.466s ahead of Kevin Magnussen's McLaren on 1m 09.515s, Kvyat's Toro Rosso on 1m 09.619s and Raikkonen on 1m 10.795s.
With Perez's five-place drop from Canada and Chilton's three, the grid will thus line up: Massa, Bottas; Rosberg, Alonso; Ricciardo, Magnussen; Kvyat, Raikkonen; Hamilton, Hulkenberg; Button, Vettel; Maldonado, Vergne; Grosjean, Perez; Sutil, Gutierrez; Bianchi, Kobayashi; Ericsson, Chilton.