Ruiz's shot bounced off the left-center field fence off Dodgers closer Jonathan Broxton, scoring Jayson Werth and Ben Francisco. The Phillies entered the eighth inning trailing 9-2.
They scored four runs in the eighth off three relievers, then four off Broxton (4-4), who began the inning by hitting Placido Polanco and walking Mike Sweeney and Werth.
Francisco, the next hitter, hit what looked like a double-play grounder to Casey Blake, but it went through the third baseman's legs for a crucial error. Ruiz then smacked a 88-mph slider to deep left to cap the comeback.
Danys Baez (3-3) pitched a scoreless inning for the win.
Matt Kemp homered among his three hits and drove in four runs to lead Los Angeles' 15-hit attack. Scott Podsednik, Andre Ethier and Jamey Carroll had two hits apiece for the Dodgers.
The bullpen kept Clayton Kershaw winless in five attempts against Philadelphia. The 22-year-old held the Phillies to two runs in 6 2-3 innings.
Los Angeles seemed to be cruising after piling on five runs over the seventh and eighth innings, but Philadelphia charged back with a four-run eighth off three Dodgers relievers before George Sherrill recovered to retire Raul Ibanez on a ground out.
Then came the ninth inning.
Broxton is 0-2 in his last five appearances while relieving Kershaw. He has given up 11 runs in 3 1-3 innings according to STATS LLC.
After Kemp went 0-for-10 in a three-game series in Washington, punctuated by a four-strikeout performance Aug. 8, Dodgers manager Joe Torre limited him to a pair of pinch-hitting appearances on Tuesday and Wednesday. The time off helped.
Kemp followed Ronnie Belliard's RBI single with another run-scoring hit, as Los Angeles built a 3-0 lead off Joe Blanton. Philadelphia pulled within a run on Ruiz's single in the fourth, but the Dodgers added a run in the top of the fifth, two in the seventh and three in the eighth.
Blanton followed his best effort of the season, in which he allowed two runs in seven innings to the Mets - with a more common rocky outing. The right-hander surrendered four runs on eight hits and four walks.
NOTES: Ibanez went 0-for-5, snapping his 18-game hitting steak. ... Placido Polanco's single in the first inning to extend his streak to 10 games. ... Shane Victorino, activated from the disabled list earlier Thursday afternoon, walked and stole second in a seventh-inning, pinch-hitting appearance.