Ramirez, who spent seven seasons with the Marlins before being dealt away July 26, broke a tie in the sixth inning with an RBI single. He added a 40-foot single with the bases loaded in the seventh.
Clayton Kershaw (10-6) allowed two runs in 6 1-3 innings to win his third consecutive start for the Dodgers. Kenley Jansen allowed two baserunners in the ninth but completed a four-hitter to earn his 23rd save in 29 chances.
Juan Rivera hit a two-run homer off Mark Buehrle (9-11), who failed for the fifth time in a row to reach the 10-win milestone for a 12th consecutive season. Buehrle allowed four runs in six innings.
Justin Ruggiano hit his 10th homer for Miami.
The Dodgers, embarking on a 10-game trip, rallied from a 1-0 deficit with four runs in the sixth. Shane Victorino led off with a double, took third on a sacrifice and scored on Matt Kemp's double. Ramirez followed with an RBI single, and Rivera hit his sixth homer.
Ramirez, who never reached the playoffs with the Marlins, drew a mix of jeers and cheers each time he stepped to the plate. One section of the ballpark began a derisive chant of his name, but it didn't catch on with the rest of the crowd of 28,130.
The Marlins intentionally walked Kemp to load the bases with two out in the seventh. When Ramirez followed with a dribbler, catcher John Buck fielded the ball but had no play, making the score 5-2.
Ruggiano hit a homer near the Marlins' home run sculpture in the first inning, a clout estimated at 430 feet. The homer was the first allowed by Kershaw in his past eight starts.
The left-hander then retired the next 14 batters.
The Dodgers led 4-1 in the sixth when Ramirez was slow fielding a grounder on a play scored as a fielder's choice. That loaded the bases with none out, but Kershaw escaped while allowing only one run, on a sacrifice fly by Carlos Lee.
Miami left the bases loaded in the seventh and finished 0 for 6 with runners in scoring position.
Lee went 0 for 3, ending his 14-game hitting streak.
Notes: Before the game, the Dodgers activated INF Adam Kennedy (groin) from the disabled list. ... Marlins SS Jose Reyes, whose 26-game hitting streak ended Thursday, sat out because of a sore right hand. He said he expected to play Saturday. ... Marlins 2B Emilio Bonifacio (sprained left thumb) said he expects to be activated as soon as he's eligible to come off the disabled list Aug. 19. ... Ruggiano's homer was the 84th off the Dodgers this year, fewest in the majors. ... Kemp had two hits and hiked his average against lefties this year to .478.