Sandberg took over when Charlie Manuel, the winningest skipper in club history, was fired on Friday. The Phillies, shut out by the Dodgers in each of Sandberg's first two games, snapped a four-game skid and won for only the fifth time in 26 games.
Andre Ethier homered for the Dodgers, who have lost just nine of their last 51.
Darin Ruf hit a home run to begin Philadelphia's comeback from a two-run deficit.
Brandon League (6-4) relieved Paco Rodriguez with one out in the ninth and nobody on. After Casper Wells reached on Ramirez's throwing error, Ruiz singled to right to put runners on first and third.
League intentionally walked pinch-hitter Jimmy Rollins to load the bases for pinch-hitter Michael Young. He grounded sharply to Ramirez, who bobbled a potential double-play ball as Wells scored to end the Dodgers' streak of 12 straight victories in one-run games.
Jonathan Papelbon (3-1) pitched a scoreless ninth, striking out two.
The Phillies snapped a scoreless streak of 21 2-3 innings when Ruf homered with two outs in the fourth to pull them to 2-1. Philadelphia tied it in the sixth on Cody Asche's groundout.
Los Angeles, beaten for only the second time in its past 21 road games, jumped out to a 1-0 lead on Ethier's homer leading off the second and added a run in the fourth on Jerry Hairston Jr.'s RBI single.
But the Dodgers didn't have much more success against Cole Hamels, who left after allowing seven hits in seven innings with eight strikeouts and no walks.
The left-hander has yielded two earned runs or less in eight of his last nine starts but continued his hard-luck trend of 2013. It was the ninth no-decision for Hamels, who entered Sunday with the fifth-worst run support (3.33 runs per game) among starters in the majors.
Ricky Nolasco had won his last three starts for the Dodgers but took a no-decision after lasting six innings. He allowed two runs on five hits with five strikeouts and one walk.