SAN FRANCISCO (AP) Hunter Pence had to holler at Denard Span mere inches ahead of him on the bases to run harder because otherwise he would get passed by his fellow outfielder on the way to home plate.

Jeff Samardzija struck out six over six innings to win for the fourth time in five starts, Pence and Span scored moments apart on Jarrett Parker's two-run double in the fifth, and the San Francisco Giants beat the Philadelphia Phillies 5-4 on Thursday night.

Buster Posey and Pence each hit RBI singles in the third to back Samardzija (8-12) as San Francisco returned from a 2-4 road trip through Washington and Miami to put together an impressive all-around win.

Pence got such a good read from first on Parker's double he sprinted around the bases so fast he wound up right on Span's heels coming into home.

''I'm at first so I'm trying to get going,'' Pence said. ''It's just one of those fun plays that's kind of a little weird but it worked out. I was yelling at him to go. Yeah, he went. He was coming back and I was like, `You gotta go,' and he started running. I was just trying to time it as close as I could behind him and try to score.''

Cameron Rupp and Nick Williams hit solo homers for the Phillies in a matchup of the two worst teams in the National League. They are two of three clubs in baseball still below 50 wins.

Rupp hit a one-out homer to the elevated right-field arcade on the first pitch he saw in the fifth from Samardzija, who had been 1-4 with an 8.67 ERA in 10 previous outings and four starts against the Phillies.

Samardzija gave up four runs and eight hits with one walk. The right-hander allowed a one-out triple to Freddy Galvis in the first but escaped the inning unscathed.

Everybody got a kick out of watching Pence on the basepaths.

''I was hoping he didn't pass him. Hunter was on a mission,'' Samardzija said.

Sam Dyson pitched the ninth for his 10th save in 11 opportunities as Giants manager Bruce Bochy gives Mark Melancon - who pitched the seventh - a break from his usual closer role after he returned from the disabled list.

Phillies starter Aaron Nola (9-8), 6-2 and not having allowed more than two earned runs in each of his previous 10 starts, had his shortest outing since also going five innings June 11. He allowed five runs and seven hits in five innings, struck out three and walked three.

''I really try not to think about that now,'' he said. ''Obviously this wasn't a great outing, a loss, but I'm just going to throw this one out the window.''

TRAINER'S ROOM

Phillies: CF Odubel Herrera, who has a 17-game hitting streak, still could need a stint on the disabled list as he nurses a tender left hamstring. He was hurt chasing down a ball Monday night at San Diego and missed his third straight game Thursday. ''We're thinking a lot about it,'' manager Pete Mackanin said. ''I'm waiting for the medical people to make that decision. I can't make it, I don't know where he's at. They work on him every day and there's still tenderness.'' ... RHP Vince Velasquez will be examined by Dr. Robert Thompson in St. Louis as he deals with an injured right middle finger that landed him on the DL on Aug. 11.

Giants: 1B Brandon Belt was examined by team doctors Wednesday and is set to begin some cardio work Friday as he recovers from a concussion. ''That's a big step to rehabbing and getting back on the field,'' Bochy said, while noting Belt will not return until completely ready given his concussion history. ... 2B Joe Panik (concussion symptoms) will be evaluated Friday. ... RHP Johnny Cueto, who has tender spots on three fingers of his pitching hand, is likely to throw 35-40 pitches in a bullpen session Friday and a rehab assignment could be next. ... 2B Miguel Gomez had been slated to begin a rehab assignment Thursday but that was postponed after he experienced trouble with his inflamed right knee while running the bases. Bochy called it a ''setback.''

UP NEXT

Phillies: RHP Zach Eflin (1-4, 5.76 ERA) doesn't have a decision in his previous two starts against San Francisco.

Giants: LHP Matt Moore (3-12, 5.71) is 0-5 in nine starts since June 20 though Bochy has opted to let him try to work out of it. Moore has never beaten the Phillies in three career outings.

---

More AP baseball: https://apnews.com/tag/MLBbaseball

Copyright 2017 by STATS. Any commercial use or distribution without the express written consent of STATS is strictly prohibited.