SAN FRANCISCO (AP) Matt Cain didn't think his 100th career victory would mean much to him until he finally got it.
Cain (3-6) struck out five and walked four on 93 pitches. He handed off to George Kontos, who allowed a leadoff single to Bryce Harper in the sixth.
''That hit me after the game was over,'' Cain said.'' I didn't think it was going to be that big of a deal but for it to take three years it feels good, it definitely feels good.
''Especially with the way it worked out today, we got to use everybody to be a part of it. It was definitely a win that we all needed very much.''
Pitcher Madison Bumgarner pinch hit for Cain leading off the bottom of the fifth and hit an opposite-field double off the wall in right. Right-hander Jeff Samardzija, who ran for Bumgarner, scored the winning run.
Cain became the sixth Giants pitcher to reach 100 wins since the franchise came to San Francisco in 1958. Juan Marichal (238), Gaylord Perry (134), Tim Lincecum (108), Kirk Rueter (105) and Mike McCormick (104) are the others.
He can't remember another time he left with a no-hitter on the line.
''My pitch count was already high in the fifth inning and I was laboring through most of the innings putting guys on and working out of jams,'' Cain said. ''The biggest thing was for us to find a way to win today and the bullpen did a great job, to be able to shut the door and get things done.''
Santiago Casilla pitched the ninth for his 24th save. Casilla was among five Giants relievers who combined to allow one run on three hits over four innings.
NL West-leading San Francisco has won two straight since losing 11 of 13 following the All-Star break.
Nationals starter Gio Gonzalez (6-9) allowed two runs (one earned), six hits and two walks in six innings for his fourth quality start in five outings.
''He's throwing strikes, not walking people and getting out of jams when he gets in them,'' Nationals manager Dusty Baker said.
The Giants won despite troubles hitting with runners in scoring position that have dogged them throughout the second half.
They were 1 for 15 with runners in scoring position Sunday and are batting .139 (19 for 137) in that department since the All-Star break.
They were hitless in their first 11 at-bats with runners in scoring position Sunday until Angel Pagan singled in Denard Span from third with one out in the bottom of the seventh to give San Francisco a 3-1 lead.
The Giants scored their first two runs on Pagan's fielder's choice grounder in the third and third baseman Anthony Rendon's throwing error in the fifth.
Left fielder Mac Williamson left with an injury in the sixth. He dropped Chris Heisey's flyball on the play but fired to third baseman Conor Gillaspie to force out Rendon. Williamson is day to day with a jammed shoulder, Giants manager Bruce Bochy said.
RESPECTING THE GAME
After getting hit in the arm by a 94-mph fastball from Casilla leading off the ninth, Nationals first baseman Ryan Zimmerman didn't take kindly to the resounding boos he got from Giants fans implying that he was trying to sell home plate umpire Jim Joyce on the call. Bochy challenged the call, but it was upheld.
''I was fired up when I got hit. That's not something I normally do,'' Zimmerman said. ''The one thing I never do is fake something like that. I have too much respect for the game.''
Nationals: 2B Daniel Murphy was out of the lineup for a second straight day. He missed Saturday's game with left leg tightness.
Giants: CF Span and SS Brandon Crawford were both out of the lineup for a second straight day on Sunday. Span suffered a quadriceps injury beating out an infield hit on Friday. Crawford suffered a bruised thumb on a swing in the same game. Both entered late in the game and are expected to be back in the lineup Tuesday after an off day. ... Rehabbing 3B Matt Duffy (out since June 21 with a left Achilles tendon strain) was scheduled to play seven innings for Triple-A Sacramento on Sunday. He played five innings on Friday.
Nationals: Washington begins a series at the Arizona Diamondbacks with RHP Stephen Strasburg (14-1, 2.68) on the hill. Strasburg was 4-1 with a 2.08 ERA in July, his best month this season.
Giants: San Francisco plays at Philadelphia on Tuesday, and LHP Bumgarner (10-6, 2.09) will pitch. He ranks second in the NL in ERA, but the Giants have lost his last three starts and are 2-6 in his last eight. They haven't lost four straight Bumgarner starts since 2013 (Aug. 7 - Sept. 3).