Ruiz, who had driven in the Phillies' first two runs of the game, hit a 3-2 pitch off lefty Will Ohman to improve the Phillies' record to 60-48 and keep them two games behind the Atlanta Braves in the National League East.
"He's got a quick bat," Phillies manager Charlie Manuel said. "This is the best I've seen him hit since he's been in the big leagues."
Ruiz said it helped that he tried to hit the ball to the middle of the field.
"That way, I can see the breaking ball better," Ruiz said.
And he hit a slider for the game-winner.
The game wasn't without its share of controversy, however. In the bottom of the ninth, third-base umpire Bob Davidson called Gaby Sanchez's grounder foul with a runner on second base, but replays showed that it could well have been fair, which would have ended the game.
After looking at replays, Davidson told a pool reporter, "In my opinion, where it goes over the bag, you can't tell. After a bounce, it came an inch or two on the fair side, but ... it was very close. But I'm right there. I know what I saw."
Marlins manager Edwin Rodriguez certainly thought that Davidson got the call wrong.
"I've been in this game for 30 years, and I have the highest respect for the umpires," Rodriguez said. "That was the worst call I've ever seen in my 30 years in baseball. That ball was a fair ball by six inches. He was never even looking at the play."
Down by two runs in the ninth inning after giving up four seventh-inning runs, the Phillies rallied dramatically to tie the game.
Placido Polanco opened the inning by reaching on shortstop Hanley Ramirez's error. Ross Gload then singled up the middle and Raul Ibanez doubled off the left-field wall to bring Philadelphia within a run.
Jayson Werth tied the game with a single through the middle. That left runners at second and third with no outs, but the Phillies couldn't put the game away.
Domonic Brown hit a bouncer to first, where Sanchez threw home to get Ibanez. Werth was then picked off second base, and Brown was caught trying to steal.
That left Ruiz at the plate wondering if he'd get another chance to affect the game.
If not for Davidson's disputed ruling, he probably wouldn't have.
Meanwhile, Roy Oswalt showed why the Phillies traded for him before last Saturday's non-waiver Trade Deadline, though he was long gone when the game was decided.
The veteran right-hander held the Marlins to three hits over 6 1/3 innings and left with a two-run lead but with runners on first and second with one out.
Both runners wound up scoring, as well as two more in the inning.
Oswalt gave up four runs in six innings in a loss to the Nationals in his first Phillies start, but he was able to pitch out of trouble more efficiently on this night.
Oswalt worked out of jams in the second and third innings. The Marlins loaded the bases with two outs in the second, only to see Oswalt strike out opposing pitcher Chris Volstad. And in the third, with runners on first and third with two outs, he struck out Cody Ross.
"I really didn't find my mechanics until the end of the game," Oswalt said.
Oswalt finished the sixth inning by breaking Dan Uggla's bat on a moving fastball, resulting in a weak grounder, and then struck out Ross.
Oswalt left in the seventh after allowing a single and a walk, then making a nifty throw to third on Ronny Paulino's sacrifice bunt attempt.
Lefty J.C. Romero replaced Oswalt, with left-handed hitter Chad Tracy announced to pinch-hit. But the Marlins switched to right-handed hitter Donnie Murphy, who promptly doubled in a run.
Manuel said he wasn't fazed by Romero having to face a right-handed hitter, because his ERA is barely over 1.00 against righties.
"But he was having trouble throwing strikes," Manuel said.
Romero walked Ramirez intentionally to fill the bases. He then walked Logan Morrison on four pitches to tie the game.
Jose Contreras replaced Romero and promptly gave up a two-run single to Sanchez.
Oswalt threw 109 pitches on a hot, humid night. He said he is going through his annual "dead-arm" period right now.
"It usually lasts about 100 innings," Oswalt said. "Sometimes it comes and goes."
Said Manuel of Oswalt: "He's good. The time he's under contract here, he's going to win a lot of games for us."
The Phillies had forged a 2-0 lead in the sixth on Ruiz's two-out double over Ross' head in center field. The catcher said he is feeling relaxed at the plate these days.
With top players like Chase Utley, Ryan Howard and Shane Victorino out with injuries, Ruiz said he talked to several teammates about "keeping the same energy" on the team.
"Every game is big for us," Ruiz said. "I said, 'We've got to keep going and put everything together so when they come back, everything will be better.'"
Mike Sweeney, acquired on Wednesday in a trade with the Mariners, made his Phillies debut in the eighth inning as a pinch-hitter and drew a walk.