(CNN) -- Jenson Button recorded a dramatic victory during a rain-affected Hungarian Grand Prix to toast the 200th race of his Formula One career in style.
On an action packed afternoon the British McLaren driver opted for the right set of tires to negotiate a late burst of rain, while teammate Lewis Hamilton, who led for long periods, toiled.
A drive-through penalty put pay to Hamilton's hopes of winning as Button crossed the line ahead of championship leader Sebastian Vettel in his Red Bull and Ferrari's Fernando Alonso.
On the track where he won his first ever grand prix, Button's victory was his second of the Formula One season, though Vettel heads for the mid season break with a lead in the drivers' championship of 85 points.
"It's a great moment, all round a major weekend. For some reason I like these conditions. This is the first place where I won a grand prix, in 2006, in these sorts of conditions," Button told reporters.
"I'm always lucky with these conditions. You are not always going to make the right call in these conditions but I feel I'm pretty good at making the right call when it comes to tire choices -- but I'm not the only one.
"We had good pace today and I was able to make the soft tires last. The reason why we won today was because we were quick. If it didn't rain it wouldn't have made any difference."
On a wet track Vettel soon relinquished the lead after running wide on a corner and Hamilton opened up a gap over the rest of the field as he successfully handled the first two pit stops.
But on his third stop he opted for soft tires, with the track now dry in most places, while Button followed the lead of Red Bull's Mark Webber by taking on prime tires.
The difference proved crucial 20 laps later as a shower heralded a return to the slippery conditions seen earlier in the race.
Button and Hamilton wrestled for the lead, and it changed hands several times before Hamilton returned to the pits to change to intermediate tires for more grip.
And although Hamilton was ordered to observe a drive-through penalty for spinning in front of the Force India car of Paul di Resta, he used his fresh tires to good effect as he battled past Webber to finish the race in fourth place.
"Jenson was pushing me hard the whole race and the better man won today," said Hamilton. "I was struggling a lot with the graining on my left front tires. I don't know whether that was my fault by pushing too hard."
Vettel struggled with brake problems and slid off the track on several occasions but dug in to claim second and go into the mid-season break as the favorite to retain his world title.
He said: "It was more important to bring the car home but all in all it's fair to say that Ferrari and McLaren on race pace in the last couple of events have made a step forwards."
There was also drama for Nick Heidfeld as his Renault caught fire and exploded shortly after he left the pits. The German managed to leap out of his car unharmed.