The Phillies, trailing 3-2 for most of the game, pushed across a tying run in the top of the ninth when Michael Young scampered home from third on Matt Kemp's wild throw to the infield following his catch of Jimmy Rollins' short fly ball.
But the Dodgers quickly responded in the next half-inning.
Ramirez (3-for-4, three-run homer) led off with a single against Justin De Fratus (2-3) and, after Kemp struck out, went to second when Andre Ethier drew a walk.
Ellis then smoked a hit to right field. Ramirez ran through a stop stop sign put up by Dodgers third base coach Tim Wallach and easily beat the throw home for the game-winning run.
Kenly Jansen (2-3) earned the win despite yielding the score-tying run in the ninth as the Dodgers rebounded from Friday's 16-1 loss to Phillies.
Chase Utley smacked a pair of solo homers and Ben Revere went 3-for-3 for the Phillies.