Hamels (2-9) allowed one run and four hits to snap a personal six-game losing streak. The three-time All-Star lefty and 2008 World Series MVP hadn't won since April 28 at the New York Mets.
Jimmy Rollins hit a go-ahead RBI single with two outs in the seventh off A.J. Ramos (0-2). Ryan Howard followed with a two-run triple, diving headfirst into third.
Then Brown went downtown to make it 6-1. Brown has 10 homers in the last 12 games and leads the NL with 18.
The Phillies (30-30) have their first four-game winning streak and will try to go above .500 for the first time when they open a four-game series at Milwaukee on Thursday night.
Hamels has been a hard-luck pitcher this season, and his record isn't a true indicator of the way he's pitched. The Phillies haven't given him much run support and he didn't pitch with a lead between his third and 11th start. Over those nine outings, he was 1-8 with a 3.24 ERA.
It was 1-1 when Hamels was lifted for pinch-hitter Delmon Young with one out in the seventh. Ben Revere followed with a single. One out later, Rollins gave Philadelphia the lead.
Plate umpire John Hirschbeck left the game in the bottom of the seventh after a pitch missed by catcher Miguel Olivo appeared to hit him in the right hand. Hirschbeck immediately slumped to the ground and walked off the field after a few minutes. He was replaced behind the plate by second base umpire Jim Reynolds.
Derek Dietrich hit a solo homer off Hamels in the fourth.
Marlins starter Jacob Turner allowed one run and four hits in six innings. He's 1-0 with a 0.69 ERA in two starts.
The Phillies gave Hamels a rare 1-0 lead when Erik Kratz doubled in John Mayberry Jr. in the second.
Mayberry started in right field for Young a day after hitting a tying homer in the 10th inning and a grand slam to win it in the 11th. He was the first player to homer twice in extra innings since Baltimore's Mike Young in 1987.
NOTES: Hamels recorded his 23rd career double-digit strikeout game and second this season. ... Two-time Cy Young Award winner Roy Halladay is optimistic he'll pitch this season for the Phillies after shoulder surgery last month. "In my mind, there's no doubt that I won't be back this year," Halladay said. "There are still a lot of variables and unknowns. But my gut feeling is that I will be back and I can tell you that I feel a lot better than I thought at this point."... The Phillies are 9-4 vs. the last-place Marlins and 6-0-1 in series vs. Miami since being swept in a three-game set last June 29 to July 1 at Marlins Park. ... Marlins starting pitchers have a 2.12 ERA in 13 games vs. Philadelphia this season. ... Tyler Cloyd (1-2, 4.76) opens a four-game series for the Phillies in Milwaukee on Thursday night. ... The Marlins are off Thursday before going to New York for a three-game set against the Mets, who were swept in Miami last weekend.