Ramirez scored from second, ignoring third-base coach Tim Wallach's stop sign.
"That's what we teach," Dodgers manager Don Mattingly said, half-joking.
"I was ready to score," said Ramirez, who started the rally with his third hit of the game.
The Dodgers might not have needed Ellis' heroics if the catcher had produced in the fourth inning with the bases loaded and none out. Instead of bolstering a 3-1 lead, Ellis tapped into a double play that prevented a run.
But Ellis made up for it in the ninth with the sixth walk-off RBI of his career.
"I was just hoping that I would have a chance to redeem myself," Ellis said. "That at-bat really ate at me when I hit into the double play. I was kicking myself for that at-bat for a long time during the game. So to get another chance was huge."
The Dodgers also wouldn't have needed Ellis' clutch hit if they didn't squander a 3-2 lead in the top of the ninth.
Kenley Jansen blew his second save since being named closer nearly three weeks ago, though the outfield offered little help with a pair of defensive miscues.
Yasiel Puig's error in right field allowed Michael Young to reach second on a single to lead off the inning. Matt Kemp's errant throw home from center field allowed Young to score from third to tie the game at 3.
"We got away with one," Mattingly said.
Kemp, who returned from the disabled list on Tuesday, brought Ellis up the first-base line with his throw from shallow center. Young was not running home initially, but sprinted for the plate when Ellis had to range to his right to corral Kemp's throw.
Domonic Brown then laced a triple off the wall in left-center, but Jansen settled down and struck out Delmon Young to preserve the tie.
"We couldn't get the big hit," said Phillies manager Charlie Manuel.
The late-inning dramatics overshadowed another solid start from Dodgers rookie Hyun-Jin Ryu, who went toe to toe with Phillies ace Cliff Lee.
Ryu fired seven strong innings and shut down a Philadelphia offense that pounded out 21 hits and 16 runs on Friday. The left-hander struck out six and yielded seven hits for his seventh consecutive quality start.
"Ryu threw the ball great," Ellis said. "It seems like it doesn't matter if he's got his best stuff or is kind of struggling. He's going to find a way to keep you in the game and give you a chance to win. That's the mark of a winning pitcher. He's been phenomenal."
The only damage against Ryu came on a pair of solo homers by Chase Utley. The second baseman homered into the right-field pavilion in the first, and lined another solo shot into the corner in right in the third.
Lee, who entered the game with a 2.51 ERA, struck out 10 over seven innings and allowed four hits.
Ramirez continued his assault at the plate with a three-run bomb to center field in the first inning, which the Dodgers estimated at 439 feet. The shortstop also doubled in the fourth.
During an 11-game hit streak, Ramirez is batting .500 with five homers, three doubles and 14 RBIs. The Dodgers are 8-3 in during that stretch.
"Hanley is tremendous right now," Mattingly said. "He can flat out hit."
One year removed from signing with the Dodgers, Puig went 1-for-4 with a single and a run scored. Puig has 40 hits in his first 25 Major League games, three shy of Steve Sax's record for hits in a single month by a Dodgers rookie. Sax had 43 hits in August 1982.
Puig also was involved in an odd play in the sixth, when Ben Revere's rope down the right-field line bounced off the outfielder's foot and into the stands. Revere was awarded second base, though Manuel argued that Revere should have advanced to third.
A week ago, the Dodgers were 9 1/2 games back of the D-backs in the National League West. But after winning seven of the past eight, Los Angeles has climbed within five games of first place. That's the closest the Dodgers have been since early May.
"We'd be lying if we didn't know what was going on in the rest of the division," said first baseman Adrian Gonzalez. "But we're just focused on winning games."