The Brazilian lapped a three hundredths of a second quicker than Fernando Alonso in the dying seconds of the final qualifying session.
Alonso finished second while Massa was third on Sunday.
The Dutchman stopped Hamilton from winning an eighth title with a gutsy turn in the final lap.
Twice Formula One world champion Fernando Alonso said on Thursday he will decide his future shortly but dismissed media reports that he will make an announcement next week. He said reports that he would disclose his intentions in Monza next week are incorrect.
The Finn revived Ferrari's spirits with the fastest laps in free practice for Sunday's Bahrain Grand Prix.
British rookie Lewis Hamilton finished second in the Malaysian GP to hand McLaren their first one-two since 2005.
The Finn will race for McLaren next year in a straight swap with Spaniard Fernando Alonso, who has taken his place at Renault.
Formula One leader Max Verstappen passed Mercedes rival Lewis Hamilton on the penultimate lap to win a tense French Grand Prix for Red Bull on Sunday and canter 12 points clear at the top.
Kimi Raikkonen has suggested he could walk away from Formula One after losing his place at Ferrari to Spain's Fernando Alonso.
Ferrari's Michael Schumacher claimed his 67th career pole in controversial circumstances in Monaco
The record at the Nuerburgring, Germany, venue of Sunday's European Formula One Grand Prix , round five of the 18-race Formula One championship.
McLaren are in no rush to sign a successor to departed double world champion Fernando Alonso.
Honda would be interested in double Formula One world champion Fernando Alonso if he wants out of Renault and cannot move to Ferrari, team boss Ross Brawn said on Thursday. With Renault struggling to get near to the podium and without a win since 2006, Alonso's future has been under close scrutiny with the 26-year-old Spaniard eager to get back into a winning car.
Britain's Lewis Hamilton seized his first win for Mercedes in a sweltering Hungarian Grand Prix on Sunday while Red Bull's Sebastian Vettel moved 38 points clear in the Formula One championship despite finishing third.
Ferrari have extended Brazilian Felipe Massa's contract by two more years to the end of the 2010 season.
Former world champion Fernando Alonso, enjoying little success on his return to Renault, said on Monday he would decide towards the end of the season whether or not to continue with the team. The Spaniard, who had an acrimonious split from McLaren last year, is 33 points adrift of championship leader Robert Kubica in ninth place with nine points.
The 22-year-old McLaren driver needed to win or finish ahead of team mate Fernando Alonso and Kimi Raikkonen at the Chinese Grand Prix to win the world title but his race ended when he slid off the asphalt and into the gravel when approaching the pit lane.
Fernando Alonso believes this year's world title race ended when stewards decided not to punish McLaren team mate Lewis Hamilton.
The 22-year-old Briton will line up alongside Ferrari's Kimi Raikkonen on the front row for Sunday's race.
Ferrari boss Jean Todt has ruled out any prospect of Formula One world champion Fernando Alonso moving to the team from McLaren next year.
The Fuji circuit, which mixes slow corners with the longest main straight in Formula One, will allow for plenty of overtaking in Sunday's Japanese Grand Prix.
Kimi Raikkonen took pole position on an all-Ferrari front row for the Belgian Grand Prix.
The feeling in the paddock is that the FIA's World Motor Sport Council could hit them with at least a heavy fine and points penalty.
Fernando Alonso won the Italian Grand Prix while teammate Lewis Hamilton finished close on his heels on second.
Lewis Hamilton joined Massa on the front row, with Ferrari's Kimi Raikkonen lining up third.
McLaren's Fernando Alonso has been ruled out of Sunday's Bahrain Formula One Grand Prix on medical grounds following his huge crash in the Australian season-opener on March 20. The governing International Automobile Federation (FIA) said in a statement that the decision had been taken after a medical examination at the Sakhir circuit on Thursday. "Two sets of chest CT scans were compared and it was decided that there was insufficient resolution of the signs to allow him to compete on safety grounds," the statement said.
Narain Karthikeyan finished 15th for Jordan as the highest-ranked of the four men making their Grands Prix debuts in Australia.
McLaren's Lewis Hamilton led the Hungarian Grand Prix from start to finish on Sunday to stretch his championship lead over unhappy team mate Fernando Alonso to seven points.
Fernando Alonso seized pole position from McLaren team mate Lewis Hamilton at the Hungarian Grand Prix.
Fernando Alonso can take one of Michael Schumacher's many records on Sunday by becoming Formula One's youngest double world champion.
Brazilian Felipe Massa finished second for Ferrari with Australian Mark Webber third for Red Bull.
Fernando Alonso says Renault must be fully behind his bid for a second successive Formula One title this weekend because it matters more than the constructors' crown.
Renault boss Flavio Briatore dismissed rumours of Fernando Alonso moving out of the French team at the end of the 2008 season.
Michael Schumacher retired at Suzuka with an engine failure.
The Brazilian took pole position for the Japanese Grand Prix with championship-leading team mate Michael Schumacher alongside on an all-Ferrari front row.
The Formula One world champion accused Renault of twice abandoning him at crucial times this season.
Fernando Alonso did his best to put a positive spin on his disappointing return to Renault at the Australian Grand Prix on Saturday. He qualified 12th fastest for Sunday's season-opening race but will start from 11th after Toyota's Timo Glock dropped back five places for changing a gearbox.
The Spaniard said it is hard to predict the outcome of the British Grand Prix, with Ferrari resurgent after a one-two in France.