"We come out of here with a 1 1/2-game lead after coming in with a 1 1/2-game deficit," said Gonzalez. "It's a best-case scenario."
Peavy, acquired by the Giants on Saturday so he could pitch this game, came in 14-2 lifetime against the Dodgers. He was charged with four runs (three earned) in six innings.
Dodgers starter Hyun-Jin Ryu couldn't keep up with Clayton Kershaw's two-hitter or Zack Greinke's seven scoreless innings of the first two games, but he got the win anyway, improving to 12-5 while allowing three runs in six innings.
Puig's defensive switch from right field received most of the attention, because Puig has a tendency to do that. But the reworked batting order -- which followed Ramirez with Carl Crawford and Matt Kemp -- created a balanced alternation of left-handed and right-handed hitters from spots one to six and resulted in 17 runs in the three games.
Along with the pitching and hitting that won the first two games of the series, the Dodgers outhustled the Giants to the final win. Crawford scored their first run from second base on Juan Uribe's sharp single to left. Ramirez scored their final run from first base on Crawford's triple.
But the turning point came in the fifth inning when Dee Gordon -- who reached first base on a wild pitch while striking out and advanced from second to third on another wild pitch -- raced home from third base after yet another pitch in the dirt while Giants catcher Buster Posey was throwing out Gonzalez at first base.
"Dee does things nobody else thinks about doing," said Mattingly. "Guys like him and [Cincinnati's Billy] Hamilton are the only guys who know how fast they are, how much time it takes to get the ball to first and back."
It took the Giants too long, as Gordon tied the game at 2 and triggered a three-run inning that beat Peavy (1-10 overall).
"The ball didn't go too far and Posey looked at me and took his eye off me, and I went home," said Gordon. "He took his eye off me and I figured I'd be close to being safe, so I went.
Said Posey: "I feel like I glanced right as the ball bounced away. Hindsight is always 20/20 on that. If I pump-fake it, I don't know. ... Like I said, hindsight is 20/20 on those."
Mattingly said Ryu's new slider -- with a grip and arm angle copied from Kershaw -- is a weapon that has made the lefty "a handful for anybody and everybody."
Ryu -- who also tweaked his curveball with input from Josh Beckett -- said he began using the new slider in his start before the All-Star break. He's 3-0 with a 2.37 ERA in those starts.
"Ever since then, it's a go-to pitch," he said.
Kenley Jansen struck out the side for his 30th save, giving opponents something else to consider by getting Dan Uggla on a slider.
The Dodgers, unable to capitalize on Uggla's first-inning error, cashed in on his fourth-inning error. Ramirez's routine grounder went right through Uggla's legs. Ramirez was erased on a forceout grounder by Crawford, who hustled to stay out of the double play.
Crawford was singled to second by Kemp, and on Juan Uribe's sharp single to left, third-base coach Lorenzo Bundy ran Crawford on Michael Morse's arm. Crawford beat the throw home to tie the game.
The Giants bounced right back in the fourth with soft one-out singles to center by Morse and Adam Duvall, then a two-out single to left by Brandon Crawford, with Giants third-base coach Tim Flannery running Morse on Carl Crawford's arm and Morse beating his throw home.
After Gordon scored on Posey's throw to first, Puig, who didn't advance to third on that play, was singled home by Ramirez, who scored on Crawford's triple. Posey cut the lead to 4-3 with a two-out homer on a 3-0 pitch in the bottom of the fifth.