Hamilton is left to contemplate Massa's pace as the Brazilian celebrates
Ferrari's Felipe Massa became Lewis Hamilton's closest championship challenger with a copybook victory in the European Grand Prix at Valencia.
The Brazilian held off the challenge from Hamilton's McLaren throughout the race on the new Spanish street track.
Massa survived a stewards' inquiry after being released into the path of another car after his second pit stop.
BMW Sauber's Robert Kubica was third, while Ferrari's Kimi Raikkonen saw his title hopes dented with retirement.
Hamilton's lead is a point bigger than it was at the start of the race - he now leads by six points from Massa, while Raikkonen's deficit following his engine failure has grown from five points to 13.
Massa's victory was allowed to stand after an inquiry into an incident at his pit stop on lap 37, when he was released illegally into the path of Force India's Adrian Sutil.
Unusually, the stewards decided they would investigate at the end of the race.
Officials eventually chose to reprimand and fine Ferrari 10,000 euros (£7,981), ruling that the incident was unsafe but that Massa had not gained a sporting advantage.
I thought we would keep a certain gap and maintain it but he just stretched it
Massa's near-miss with Sutil may have been influenced by Ferrari's pit-stop system, in which the team do not have a "lollipop man" controlling the driver.
Instead, they use a system of lights, which are operated by the crew doing the pit stop - in such an instance, the crew have to manually over-ride the green light shown to the driver that comes on automatically when the fuel nozzle is removed.
Out on the track, Massa and Hamilton staged their own private battle at the front of the field, but the Ferrari driver was always just that bit too fast for his rival.
Massa consolidated his pole position into a lead on the first lap as Hamilton, starting on the dirty side of the track, was forced to defend his second place from Kubica.
Massa then proceeded to edge away from Hamilton until he had a lead of nearly five seconds by the time of his first pit stop on lap 15, two laps earlier than Hamilton's first stop.
But despite two superbly quick laps from the McLaren driver before he came into the pits, the margin between the two was reduced by only a second when Hamilton rejoined.
And Massa was even stronger in the second stint, pulling away from Hamilton in a more convincing fashion to be more than eight seconds in front by the time of his second stop on lap 37.
Massa led comfortably from Hamilton throughout the race
The Ferrari driver regained his lead when Hamilton stopped two laps later and cruised to his fourth victory of the year - the same number as Hamilton.
"I can't complain with second place," Hamilton said.
"We've had quite a strong weekend. I've had a traumatised weekend - I've had a problem health-wise.
"But we got some good points this weekend and so it was solid for us.
"I got a reasonably decent start but I just had to try and hold my spot but after that I was able to relax and try and attack and keep up with Massa.
"I thought we would keep a certain gap and maintain it but he just stretched it."
Massa was thrilled to make up for the disappointment of losing a win in the last race in Hungary when his engine failed with three laps to go.
"It's amazing after such a bad result," Massa said. "We've come here to a new track and did a fantastic job; preparing the car in the sessions and choosing the right tyres, which was pretty difficult.
"Then making the pole and winning the race and making the fastest lap there is nothing more we can ask for."
Ferrari's pit stop system also came under the spotlight when Raikkonen made his final stop - the Finn left while the refuelling hose was still attached.
He had pitted at the same time as McLaren's Heikki Kovalainen, who he had been attempting to pass for fourth place.
But in his keenness to get out of the pits ahead of his fellow Finn, Raikkonen knocked over one of the two men holding the refuelling hose, and had to stop again and he lost a place to Toyota's Jarno Trulli.
A Ferrari spokesman said Raikkonen had left the pits before being given the green light by the pit system.
The mechanic, Piero Timpini, suffered a broken toe and a sore back.
There was worse to come for Raikkonen, when his engine failed a couple of laps later.
In the race, Raikkonen, who has not won since the Spanish Grand Prix in April, suffered again for his inability to string a competitive lap together in qualifying.
The Finn was held up behind Kovalainen in the first stint of the race, but had a particularly poor second stint, when he lapped the best part of a second slower than Massa despite being on a clear track.
It was a disastrous race for Raikkonen, who retired with engine failure
Kubica drove a lonely race, unable to challenge the leaders, but comfortably clear of the pursuing Kovalainen and Raikkonen.
Following Raikkonen's retirement, Kovalainen was comfortable in fourth, ahead of Toyota's Jarno Trulli and Toro Rosso's Sebastien Vettel, who lost out to the Italian during the first pit stops.
Toyota's Timo Glock and Williams's Nico Rosberg took the final points positions.
Home favourite Fernando Alonso, the reason Spain has landed a second race, had a miserable weekend in his Renault.
After qualifying a lowly 12th, the double world champion was hit from behind by Williams driver Kazuki Nakajima on the opening lap.
The incident knocked off Alonso's rear wing and damaged his suspension and gearbox, forcing him into retirement.
Result from European Grand Prix at Valencia:
1. Felipe Massa (Brz) Ferrari one hour 35 minutes 32.339 seconds
2. Lewis Hamilton (GB) McLaren-Mercedes at 5.611secs
3. Robert Kubica (Pol) BMW Sauber at 37.353
4. Heikki Kovalainen (Fin) McLaren-Mercedes at 39.703
5. Jarno Trulli (Ita) Toyota at 50.684
6. Sebastian Vettel (Ger) Toro Rosso-Ferrari at 52.625
7. Timo Glock (Ger) Toyota at 1:07.990
8. Nico Rosberg (Ger) Williams-Toyota at 1:11.457
9. Nick Heidfeld (Ger) BMW Sauber at 1:22.177
10. Sebastien Bourdais (Fra) Toro Rosso-Ferrari 1:29.794
11. Nelson Piquet Jr (Brz) Renault 1:32.717
12. Mark Webber (Aus) Red Bull-Renault one lap behind
13. Jenson Button (GB) Honda one lap
14. Giancarlo Fisichella (Ita) Force India-Ferrari one lap
15. Kazuki Nakajima (Jpn) Williams-Toyota one lap
16. Rubens Barrichello (Brz) Honda one lap
17. David Coulthard (GB) Red Bull-Renault one lap
R Kimi Raikkonen (Fin) Ferrari 45 laps completed
R Adrian Sutil (Ger) Force India-Ferrari 41 laps completed
R Fernando Alonso (Spa) Renault one lap completed
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.