A ruling by third base umpire Bob Davidson cost the Marlins a victory in the ninth. Gaby Sanchez pulled a grounder over third base for a hit that would have scored Hanley Ramirez from second base, but Davidson ruled the ball foul.
Marlins manager Edwin Rodriguez argued in vain, and replays showed ball landed inside the line behind the base.
Ruiz took advantage of the break, hitting his fifth homer off Will Ohman (0-1). Ruiz also had a two-run double in the sixth. Brad Lidge gave up a leadoff single in the 10th to Mike Stanton, who stole second but was stranded there. Lidge earned his 12th save in 16 chances.
Roy Oswalt, making his second start for the Phillies since being acquired in a trade with Houston, took a 2-0 lead into the seventh before Florida rallied for a 4-2 lead.
Philadelphia scored twice in the ninth to tie the game with none out, then put the brakes on the rallly by having three baserunners thrown out.
The Phillies won despite stranding 11 runners. They remained two games behind NL East leader Atlanta and earned their seventh sweep of the year.
Despite a rash of injuries, Philadelphia has won 12 of its past 14 games. The Marlins went 2 for 14 with runners in scoring position and lost their fourth game in a row.
Philadelphia rallied from a 4-2 deficit in the ninth. Placido Polanco reached to start the inning when shortstop Ramirez made a bad throw for his 14th error this season. Ross Gload singled off Leo Nunez, and a double by Raul Ibanez scored a run. Jayson Werth singled in the tying run.
Then the Phillies self-destructed on the basepaths. Ibanez was caught off third on a grounder and tagged out, Werth was picked off second and Domonic Brown was thrown out trying to steal second. After Davidson's blown call in the bottom of the ninth, Ryan Madson (4-1) struck out Sanchez and Cody Ross struck out to end the inning.
Oswalt allowed two runs in 6 1-3 innings. He retired 10 in a row before Stanton singled to start the seventh. Pinch-hitter Donnie Murphy hit an RBI double, J.C. Romero walked in a run and Sanchez hit a two-run single.
Ruiz doubled home the only two runs off Chris Volstad, who went 5 2-3 innings. The Phillies loaded the bases with one out in the first but failed to score, and they left the bases loaded in the sixth.
A hustling defensive play by Ramirez helped Florida in the fourth. The shortstop sprinted into deep left field to retrieve a double off the wall by Ruiz, then threw to third and nabbed Ruiz trying to stretch the hit into a triple.
NOTES: Murphy improved to 5 for 12 as a pinch hitter with seven RBIs. ... Ibanez extended his hitting streak to 13 games with a single in the third. ... Gload went 1 for 5 batting third for first time this year. ... Ramirez went hitless, and since July 2 he's batting .216 (24-111) with two extra-base hits.