Hamilton took full advantage of the damp conditions in Hungary to control the first half of the race, but it was Button who made it consecutive wins for McLaren as Red Bull struggled to keep up yet again.
Sebastian Vettel took the pole position from Hamilton and Button on Saturday and made a fantastic start in difficult conditions with light rain falling as the race got underway.
The Red Bull driver was quickly caught by Hamilton, though, as the McLaren driver proved that Red Bull seem to lose their advantage in wet conditions.
It took only five laps before an error from Vettel allowed Hamilton to pass and take the race lead, with team-mate Button sitting in third.
An early spin from Felipe Massa sent him back down the field to ninth, as Fernando Alonso made up for a poor start to regain his position from Nico Rosberg to take fourth place.
As the track dried and drivers switched to slick tyres, Mark Webber used all his experience to come in first and gain a place on Alonso as Rosberg slipped out of the top five.
As the top five spread out enough to prevent any real battles on the track, some additional drama was provided by Nick Hiedfeld, whose car caught fire upon leaving the pit-lane.
The German driver jumped from his car just in time, as the fire caused a small explosion that seemed to injure one of the race stewards attempting to put out the fire.
The race seemed in danger of becoming something of a precession before a burst of rain over the Hungaroring cost Hamilton the race.
The shower caused Hamilton to spin as his wheels touched the slippery curbs, allowing teammate Button through to lead the race.
This led to a series of overtakes, with Hamilton regaining the lead before Button powered past yet again with the assistance of DRS as the two McLaren drivers battled for the lead.
As the rain continued to fall over sections of the track, Hamilton chose to stop and change into intermediate tyres, leaving Button to lead the race.
As the rain stopped almost immediately, that was the wrong move for Hamilton, and he was forced to stop again as Alonso eased past him in dry tyres.
As if that was not enough for Hamilton, he was given a drive through penalty after he forced Paul Di Riesta off the track whilst recovering from his earlier spin.
That left Hamilton languishing in sixth place with only 11 laps left in the race.
Button took full advantage of the mistake by his teammate to lead the race and pull away from Vettel to take the victory in his 200th grand prix.
Hamilton did pick up a couple of places over Massa and Webber, but failed to reach the podium as Vettel eased home to second and Alonso took a comfortable third almost a lap ahead of Hamilton.
The result means Vettel further extends his lead in the championship, pulling further ahead of teammate Webber and Alonso of Ferrari, who sit in second and third respectively.
Button, who had not finished the previous two races, gained 15 points on teammate Hamilton, who is now only 10 points ahead his fellow Brit. But as the sport heads into the mid-season break, it is still Vettel who controls the table with a lead of 85 points.