Mayberry tied it off Steve Cishek in the 10th after Juan Pierre scored on a wild pitch in the top of the inning.
Domonic Brown reached on a fielding error by pitcher Edgar Olmos (0-1) with one out in the 11th and advanced on pinch-hitter Kyle Kendrick's sacrifice. After Freddy Galvis was intentionally walked, Erik Kratz walked to load the bases.
Mayberry followed with a line-drive homer to left. He circled the bases and was mobbed by teammates at the plate.
Michael Stutes (1-0) pitched a scoreless inning for the win.
Brown, who had eight homers in the previous eight games, was 0 for 5 for Philadelphia and made an error in left field. But the Phillies won their third straight to move within a game of .500. They haven't been even all season.
A disputed call in the eighth went against the Phillies and drew the ire of the crowd. Ben Revere was called for interfering with second baseman Derek Dietrich while breaking up a double play although he slid headfirst and didn't appear to go out of his way or make much contact. Michael Young beat the throw to first, but umpire Bob Davidson called an automatic double play.
Manager Charlie Manuel argued briefly and fans booed loudly and hurled a derogatory chant at Davidson.
The last-place Marlins have lost two in a row since a three-game sweep over the New York Mets.
Phillies rookie starter Jonathan Pettibone allowed two runs - one earned - and seven hits in six innings.
Miami's Ricky Nolasco gave up two runs and four hits, striking out six in 6 2-3 innings.
Down 2-0, Ryan Howard started Philadelphia's rally by lining a double leading off the bottom of the seventh. After Brown struck out, Delmon Young hit an RBI double high off the wall in left-center.
Nolasco then fanned Galvis, but pinch-hitter Kratz hit an RBI double that just missed clearing the right-field wall to tie it at 2. Kratz ran in from the bullpen right before his name was announced, grabbed a bat and went up to the plate.
Galvis saved three runs with outstanding plays at second base. With runners at second and third and two outs in the eighth, he made a sliding backhanded grab on Casey Kotchman's bouncer up the middle and threw him out.
His first gem came with a runner on third, one out and the infield up in the second. Galvis snared Adeiny Hechavarria's hard one-hopper, held the runner and got the second out.
For the second night in a row, the Marlins jumped ahead 2-0 and couldn't hold it.