Bryan De La Cruz added two hits for the Marlins, who improved to 73-68.
Marlins starter Eury Perez gave up four hits and two runs with four strikeouts and three walks in five innings.
David Robertson (5-6) earned the win in relief, with Tanner Scott throwing a scoreless ninth inning for his sixth save in nine chances.
Trea Turner homered, singled, stole a base and scored two runs for the Phillies. Bryce Harper contributed an RBI single, but Philadelphia fell to 77-63.
Phillies starter Cristopher Sanchez tossed five innings and allowed four hits with four strikeouts and one walk. Matt Strahm (8-4) took the loss, allowing Stallings' home run in the seventh for a 3-2 Marlins advantage.
In the ninth, pinch hitter Cristian Pache flied out to left, Johan Rojas grounded out to first and Kyle Schwarber struck out.
The Marlins appeared on the verge of a two-run lead in the first, but second baseman Bryson Stott made a diving catch against Yuli Gurriel to end the inning. There were runners on second and third when Gurriel lined out.
The Phillies went ahead 1-0 in the bottom of the first when Turner launched a solo homer to left. It was Turner's first at-bat since he missed two games after being placed on the paternity list.
In the third, Harper blooped an RBI single to center for a 2-0 advantage.
Miami placed runners on first and second with one out in the fourth, but Jazz Chisholm Jr. struck out and Jon Berti grounded out to Sanchez.
The Marlins tied the game at 2 in the sixth when Sanchez hit a two-run homer to right-center off Seranthony Dominguez.
Philadelphia loaded the bases with two outs in the bottom of the seventh, but Nick Castellanos grounded out to shortstop to end the threat.
—Field Level Media