The homer -- Ramirez's 31st this season and sixth since the Dodgers traded to get him from Boston at the July 31 trading deadline -- broke up a scoreless tie with two outs in the top of the fifth inning. He added a two-run ground rule double in the sixth.
Russell Martin and Andre Ethier both drew bases loaded walks for one RBI apiece and, like Ramirez, Matt Kemp had two hits for the Dodgers, who overtook the Diamondbacks atop the NL West Division with their second win in the key three-game series.
Winner Chad Billingsley (14-10) surrendered four hits in 6 1/3 scoreless innings with one walk and nine strikeouts.
Arizona's Justin Upton hit a two-run ninth-inning single. He had two of the six hits for the Diamondbacks, who have dropped seven of 10.
The losing pitcher was Brandon Webb (19-7).