The Giants got even -- and then some -- on Monday night.
Matt Cain pitched effectively into the seventh inning, and the Giants supported him with a four-run fourth inning that included a two-run infield single, leading to an 8-4 victory in the opener of a three-game series.
"We did a lot of good things," Giants manager Bruce Bochy said. "We were very aggressive on the bases. Things got a little strange there. The guys were aggressive."
Cain (3-1), who beat the Dodgers 2-1 on April 24, was equally effective in the rematch, limiting the National League West rival to one run on five hits over 6 2/3 innings. He walked three and struck out five.
Along the way, the 32-year-old pitched his 2,000th career inning, becoming the 12th player in Giants franchise history to reach the milestone.
"It's been a long road," the oft-injured Cain said after he lowered his home ERA in four starts this season to 1.19. "I've been grinding it out, and the guys here have really helped."
The Giants gave Cain the big offensive boost he needed with their four-run fourth off Dodgers right-hander Brandon McCarthy, who was reinstated from the disabled list before the game.
With the score tied at 1-1, Brandon Belt and Posey got the uprising started with consecutive singles. Belt scored the tiebreaking run on a double by Brandon Crawford, setting up the key play of the night.
Nunez grounded weakly up the middle of the diamond, a ball Dodgers shortstop Corey Seager was able to field 10 feet onto the outfield grass behind second base.
Posey scored on the hit, and as Crawford also raced for home, Seager threw toward the plate, only to have the ball cut off by McCarthy near the pitcher's mound.
"He shouldn't have been in the middle of the diamond," Dodgers manager Dave Roberts said of McCarthy. "The mechanics of the play, he should have been behind home plate, so that's where it got funky from the beginning."
Unaware that he easily could have thrown out Crawford at the plate, McCarthy unsuccessfully went after Nunez at second base.
The play was ruled a two-run single, and it produced a 4-1 lead.
After Nunez stole third base, he scored the inning's fourth run on a sacrifice fly by Christian Arroyo.
"We got a couple of bleeder hits," Cain said, "but you need that to get you going. ...
"We've been playing well. The guys have been able to come through with big hits. The big two-out hit, or the two-out out (by the defense) -- something we have to keep doing."
Posey's homer, his seventh of the season, came in a two-run seventh inning. Nunez capped the Giants' scoring with a double that plated Crawford, who had walked.
Posey, Nunez and Mac Williamson had two hits apiece for the Giants, who improved to 10-9 at home this season.
Chris Taylor had three hits, including an RBI double in a three-run ninth inning, for the Dodgers, who began a seven-game trip with a 2-2 split at Colorado over the previous four days.
Pitching for the first time since April 29 after recovering from soreness in his left shoulder, McCarthy (3-1) was roughed up for six runs and eight hits in 5 2/3 innings. He walked one and struck out five.
"That fourth inning got away from him," Roberts said of McCarthy. "I think if you look back at that inning, there were only a couple of balls hit hard. That fourth inning obviously proved to be the difference."
NOTES: The four-game winning streak is the Giants' longest since the last four games of the 2016 regular season. ... The last Giants pitcher to reach 2,000 innings for the franchise was RHP Gaylord Perry in 1970. ... Before the game, the Giants placed RF Hunter Pence (strained right hamstring) on the 10-day disabled list and summoned OF Mac Williamson from Triple-A Sacramento. ... Dodgers LHP Alex Wood was named National League Player of the Week for the period ending Sunday. Wood went 2-0 last week, striking out 21 in 11 scoreless innings. ... In order to create a roster spot for RHP Brandon McCarthy, the Dodgers demoted OF Brett Eibner to Triple-A Oklahoma City. ... The Dodgers are expected to reinstate LHP Rich Hill (blister on left middle finger) from the DL to start Tuesday. ... Dodgers 1B Adrian Gonzalez (sore right elbow) and 2B Logan Forsythe (fractured right big toe) are set to begin rehab assignments with Class A Rancho Cucamonga on Tuesday.