PHILADELPHIA (AP) Jeff Samardzija saved a depleted bullpen.
The right-hander tossed three-hit ball over six scoreless innings, Buster Posey, Pablo Sandoval and Kevin Pillar homered in a five-run fifth and the short-handed San Francisco Giants beat the Philadelphia Phillies 5-1 Wednesday night.
The Giants were down three relievers after a flurry of moves before the trade deadline but Samardzija (8-8) handcuffed Philadelphia for his fifth straight road win.
"He did a terrific job," Giants manager Bruce Bochy said. "He had great command, life on the fastball, a cutter. He gave us what we needed. It couldn't work out better."
San Francisco finished July 19-6, the best record in the majors, and gained ground in the NL wild-card standings after entering 2 1/2 games behind.
"We're playing winning baseball," Samardzija said. "I like our mentality right now and how we're approaching each day."
The Phillies fell a half-game back of Washington for the top spot in the wild-card race and were a half-game behind the Cubs, who could move ahead of the Nationals into the top spot with a win at St. Louis.
Vince Velasquez (3-6) took a three-hitter into the sixth before walking Mike Yastrzemski. Posey then ripped a 2-1 fastball out to left field for only his sixth homer in 273 at-bats this season.
Adam Morgan replaced Velasquez, and Sandoval went deep to right for his 14th homer. Brandon Crawford followed with a single and then Pillar connected, sending his 13th homer out to left to make it 5-0.
"I don't think Morgan had his best stuff," Phillies manager Gabe Kapler said.
Tony Watson replaced Samardzija to start the seventh and walked Bryce Harper before J.T. Realmuto hit a double. But the Phillies only managed one run on Adam Haseley's RBI groundout.
Reyes Moronta worked the eighth and Will Smith pitched the ninth.
The Giants traded former closer Mark Melancon to Atlanta, left-hander Drew Pomeranz and minor league righty Ray Black to Milwaukee, and righty Sam Dyson to the Twins.
"It was a busy day, had to say a lot of byes, but they kept their focus and won a game," Bochy said.
Bochy joked before the game that Sandoval was available to pitch a couple of innings. The cleanup hitter hasn't allowed a run in two innings of mop-up duty over the past two seasons.
Velasquez pitched out of a bases-loaded, one-out jam in the third by striking out Yastrzemski and Posey, but they got to him in the sixth.
"I fell behind in the count and that led to the homer," Velasquez said. "That's where you tip your cap to a great hitter."