SAN FRANCISCO (AP) -- Clint Barmes gave Charlie Morton a chance to stay in the game.
Barmes hit a three-run home run in the seventh inning, Morton pitched into the eighth and the Pittsburgh Pirates beat the San Francisco Giants 3-1 on Friday night.
Barmes came up with two runners on and Morton in the on-deck circle. The home run gave Pittsburgh the lead and helped prevent manager Clint Hurdle from going to a pinch hitter.
''I was looking to stay inside,'' Barmes said. ''My mindset at that time was to at least get one of them in, to at least tie it. I saw the slider pretty well. It was a pretty good pitch but I was able to drop the barrel on it and stay inside of it.''
Andrew McCutchen and Josh Harrison each had two hits for the Pirates, who have won four of five and maintained their one-game lead over the St. Louis Cardinals in the NL Central.
Morton (5-3) allowed one run on seven hits, two after the Giants scored their first run, over 7 2-3 innings. He walked one and struck out three.
''I was pretty efficient and the guys were making good plays,'' Morton said. ''It all added up to me going pretty deep. My whole game plan is to keep the ball on the ground.''
Over his last four starts, Morton has given up 56 groundballs and 17 flyballs.
Madison Bumgarner (11-8) took a shutout into the seventh and wound up allowing three runs on seven hits over eight innings. He walked four and struck out five.
''I thought I made a good pitch,'' Bumgarner said. ''It was pretty much where I wanted it. He just made an adjustment. That's what makes them so good, there is no one way to beat them.''
Roger Kieschnick drove in a run for the Giants, who have lost three straight and five of six overall. Hunter Pence added a pair of hits.
Morton, who has worked through hip and wrist issues, improved to 4-1 over his last eight starts with his longest outing of the season.
''I was very happy for Barmes,'' Morton said. ''We all were, because he's worked so hard. To see him put that swing on the ball, it was a thing of beauty. If he doesn't hit that, I'm out.''
Mark Melancon pitched the ninth for his ninth save in 11 chances.
The Giants broke through in the fourth. Buster Posey hit a one-out double and advanced to third on a wild pitch. He scored when Kieschnick's blooper fell safely in short left field.
The Giants had runners on in each of the first four innings. Following Kieschnick's RBI single, Morton retired 12 of the next 13 before giving up a double to Brandon Crawford with two outs in the eighth.
Tony Watson entered the game and struck out Brandon Belt to end the inning.
Bumgarner retired 14 of 16 before giving up consecutive singles to Gaby Sanchez and Harrison ahead of Barmes' three-run shot in the seventh.
Russell Martin has thrown out a major-league leading 26 runners after getting both Hunter Pence and Gregor Blanco.
McCutchen extended his hitting streak against the Giants to 10 games and is hitting .475 (19 for 40) over that stretch.
NOTES: Pirates RHP Jason Grilli is scheduled for a bullpen session on Sunday and could throw a simulated game in his following appearance. ... Pirates OF Starling Marte has not played in five days because of a right hand contusion. Marte leads the league in hitting (.407) against left-handers. ... Pirates IF Jordy Mercer made his first MLB start at 3B. ... LHP Francisco Liriano (14-5, 2.53) gets the start against the Giants, the team who signed him, on Sunday. ... RHP Tim Lincecum (6-13, 4.53) goes for the Giants on Saturday. ... RHP Yusmeiro Petit was recalled from Triple-A Fresno to replace Giants RHP Matt Cain, who went on the DL. The Giants also recalled LHP Mike Kickham and optioned IF Nick Noonan. ... Giants LHP Jeremy Affeldt (groin strain) is close to resuming baseball activities and could return to the bullpen Sept. 1. ... Giants OF Angel Pagan (left hamstring surgery) had his rehab transferred to Fresno from the Arizona Rookie League.