SAN FRANCISCO -- The Washington Nationals took advantage of Matt Cain's wildness to score three runs in the first inning, and right-hander Tanner Roark never relinquished the lead while pitching six-plus innings of seven-hit ball in a 6-2 victory over the San Francisco Giants on Wednesday night.

The win was the third in as many nights for the leaders of the National League East over the top team in the West. The Nationals (35-29) are assured of a second series win over the Giants at AT&T Park in the last three years.

The three-game losing streak is just the second of the season for the Giants, who nonetheless retain the best record in baseball at 42-24.

The Nationals, taking advantage of eight walks, won for the 10th time in 12 games -- even though they were out-hit 8-6.

Washington right fielder Jayson Werth drove in three runs with a solo home run and a two-run single.

Coming off the best effort of his career in a 6-0 win over the San Diego Padres, Roark (5-4) was nearly as good against the Giants, limiting them to one run before handing the ball over to his bullpen with a three-run lead and two runners on base in the seventh inning.

Roark didn't walk a batter for his second consecutive start, and he struck out four while improving his record against NL West squads to 4-0 in five career appearances.

Roark got big-time help from the Washington defense. A diving stop by second baseman Danny Espinosa in the fourth inning and a diving catch by left fielder Ryan Zimmerman in the sixth prevented at least one Giants run apiece.

The Nationals bullpen, which began the day leading all of baseball in ERA, also rescued Roark. Right-hander Drew Storen inherited a two-on, none-out situation in the seventh and managed to lose only one run off a 4-1 lead, that coming on a two-out, pinch-hit single by Pablo Sandoval that scored second baseman Brandon Hicks.

Storen got Giants third baseman Joaquin Arias to ground into a double play and center fielder Angel Pagan to pop to short left field, sandwiching Sandoval's RBI hit.

Right-hander Tyler Clippard pitched a perfect eighth inning, and lefty Jerry Blevins threw a 1-2-3 ninth for Washington, which improved to 5-1 on its current 10-game trip.

Nationals pitchers did not walk a batter in the game.

Washington gave Blevins a four-run cushion with which to work thanks to Werth's two-out, two-strike single up the middle in the top of the ninth. Giants relievers walked three in the inning, including Nationals center fielder Denard Span, who for the second time in the game scored a run after being issued a free pass.

Werth hit a solo home run off Cain (1-4) in the fifth inning, equaling the number of hits it took for Washington to grab a 3-0 lead in the top of the first.

All three runs were scored by Nationals hitters who walked, as Cain became the first Giant in 13 years to issue free passes to each of the first three batters in a game and then see them all score.

First baseman Michael Morse had a single and a double for the Giants, who

Cain was pulled after five innings, having thrown 102 pitches. He gave up four runs and three hits but walked a season-high five. He struck out four.

NOTES: Despite being outscored 17-5 by the Nationals in the first three games of the series, the Giants remain No. 1 in the National League in run differential at plus-53, with Washington second at plus-50. ... The Nationals placed C Wilson Ramos on the 15-day disabled list with a strained right hamstring. Ramos suffered the injury running out a double in the ninth inning Tuesday. ... Washington recalled C Sandy Leon from Triple-A Syracuse. ... Giants 3B Pablo Sandoval was a late scratch from the starting lineup because of an illness. Sandoval singled as a pinch hitter. ... The Giants dealt LHP David Huff to the New York Yankees in a cash transaction. Huff made 16 appearances for San Francisco this season, compiling a 1-0 record and a 6.30 ERA before being designated for assignment last week. ... Before the game, Giants C Buster Posey donated 1,000 gloves to the Giants Community Fund's Junior Giants program.