Lewis Hamilton battled through a bad start and late-race rain to win an action-packed British Grand Prix in front of a capacity Silverstone crowd.
Hamilton had to pass both Williams cars after a bad start and losing a place at the re-start after an early safety car.
But the world champion fought back to take the lead at the first pit stops.
Rain made for a chaotic end to the race but Hamilton came through to win from Mercedes team-mate Nico Rosberg and Ferrari's Sebastian Vettel.
The world champion's fifth win of the season was greeted with roars of delight from the 140,000 fans packed into the track. It moves him 17 points clear of Rosberg in the championship.
Hamilton admitted the Mercedes' bad starts had "made the race for the fans" and, as thousands streamed on to the track to salute him on the podium, he said: "Thank you for coming out today and making my whole weekend, I really wanted to do it for you guys. I couldn't have done it without you. I'm so elated. You can't imagine how happy I am. I was tearing up on the last lap."
Hamilton's path to victory was far from smooth, however, as Massa leapt into the lead past both Mercedes from third on the grid.
Hamilton fended off a challenge from Bottas for second on the first lap, at the end of which the safety car was deployed because of a pile-up at the first corner, involving both Lotuses and both McLarens.
Three of the four cars were taken out of the race in one go, with Lotus team-mates Romain Grosjean and Pastor Maldonado appearing to collide and McLaren's Fernando Alonso half-spinning as he took avoiding action and collecting team-mate Jenson Button, whose car also retired.
Alonso was able to continue, but needed to pit for a new front wing, although the late rain shower helped the double champion beat Sauber's Marcus Ericsson to finish 10th and score his first points of a difficult year in the uncompetitive and unreliable McLaren-Honda.
At the restart, Hamilton tried an aggressive move on Massa immediately after the safety car line, which indicates the place from which drivers can begin to race and at Silverstone is on the entry to the final Vale/Club corner complex.
But Hamilton overcooked it, ran briefly off the track, and Bottas took advantage and sneaked through into second.
Bottas was initially told he could not try to pass Massa, only for Williams to relent and allow them to race.
But the Finn could not pass the Brazilian as the two silver Mercedes tracked the two white Williams to the first pit stop period.
Hamilton was brought in first, on lap 19, and the so-called 'undercut' worked perfectly as he produced what Williams technical chief Pat Symonds called a "stunning" in-lap.
A quick pit stop and a strong first lap out of the pits meant that when Massa and Rosberg pitted on the next lap Hamilton passed them before they were out of the pits.
Rosberg came oh-so-close to beating Massa out - the two cars were side by side as they went down the pits, but Massa had the inside line for the corner where the pit lane rejoins the track and held on to second.
Even worse for Rosberg, when Bottas stopped on the next lap, the Finn rejoined also ahead of the Mercedes and although Rosberg overtook him into Turn Four, Bottas got straight back in front through the kink at Turn Five.
Rosberg stayed stuck in fourth place until lap 36 of 52 when light rain began to fall.
At first, it hit only the northern part of the track at Luffield, Woodcote and Copse corners but a wobble from Bottas at Copse gave Rosberg the chance he needed and he took third, and then a couple of laps later moved into second past Massa at Turn Three.
The rain, which stopped and then returned with greater intensity over the whole of the track, was bad news for Williams, both of whose cars were passed by Vettel as the teams juggled with tyre choices in the intermittent rain at the end of the race.
It was an unexpected surprise for Ferrari at the end of one of their least competitive races of the season.
Massa took fourth ahead of Bottas, from Red Bull's Daniil Kvyat, Force India's Nico Hulkenberg and the second Ferrari of Kimi Raikkonen.