SAN FRANCISCO (AP) — Matt Duffy homered among his three hits and drove in three runs, Hunter Pence also had a homer and the San Francisco Giants beat the Washington Nationals 8-5 Friday night.

Gregor Blanco added three hits and drove in two runs for the Giants, who have won three of four since being swept in a four-game series by the Cubs in Chicago.

Bryce Harper homered and drove in four runs and Danny Espinosa also went deep for the Nationals, who lost their fourth straight and fifth in the last six.

Max Scherzer (11-9), facing the Giants for the first time since Game 4 of the 2012 World Series, gave up a season-high six runs on seven hits over three innings. He allowed two home runs and has given up five over his past two starts after giving up 13 through his first 22 starts. Scherzer struck out three and did not walk a batter.

Giants starter Matt Cain failed to finish the fifth inning for a second straight start, allowing five runs on six hits in 4 2/3 innings. He walked one and struck out three. Cain has given up 18 runs over his last four starts and has a ERA of 8.24 over that stretch.

Jeremy Affeldt (2-2) took over for Cain in the fifth and pitched an inning to get the win.

Harper's 30th home run, a three-run shot in the fifth, pulled the Nationals to 6-5. Cain allowed two more baserunners — including one that reached on an error — before Affeldt ended the threat.

Harper, who hit a sacrifice fly in the first, became the 37th player to hit as many as 30 home runs as a 22-year old.

Duffy, who committed two of the Giants' three errors, homered in the first, doubled in a run in the second, singled in the fourth and hit a sacrifice fly in the eighth.

TRAINER'S ROOM

Nationals: OF Reed Johnson (left calf strain) went 0 for 2 in his first rehab start with Single-A Potomac on Thursday night and took Friday night off. ... RHP David Carpenter is close to pitching off a mound.

Giants: RHP Tim Hudson (right shoulder strain) allowed one hit in 2 2/3 scoreless innings in a rehab start with the Single-A San Jose Giants. He threw 31 pitches, 22 for strikes, and struck out two. ... C Andrew Susac (right thumb sprain) went 2 for 4, including a two-run homer, in the same game. He's expected to play for Triple-A Sacramento on Saturday.

FOR A SECOND

Nationals infielder Dan Uggla, currently on the disabled list with a back issue, was presented with a World Series ring by the Giants on Friday night. Uggla appeared in four games last year with the defending champions, going 0 for 12 with a run scored and a walk.

UP NEXT

Nationals: LHP Gio Gonzalez (9-4, 3.50) goes for his sixth consecutive win Saturday. Gonzalez, who threw eight scoreless innings against the Los Angeles Dodgers in his last start, has an ERA of 1.48 over his last eight starts.

Giants: RHP Jake Peavy (2-5, 3.75) is 2-3 with a 2.74 ERA since coming off the disabled list July 3. He's 4-6 with a 3.79 ERA in 13 games against the Nationals.