PHILADELPHIA -- 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."
Phillies closer Hector Neris plans to drop his appeal of a three-game suspension for intentionally throwing a pitch at David Freese on July 16. He'll begin serving Thursday.
MAD BUM STAYS
The Giants kept 2014 World Series MVP Madison Bumgarner even though he'll be a free agent after the season. Following a recent run of success, the team is contending in Bochy's final season before retirement.
"He means so much to me," Bochy said. "To have him here the rest of my tenure here, it's pretty cool. It makes me feel really good to have him beside me."
Giants: Acquired 2018 All-Star 2B Scooter Gennett from the Reds, INF Mauricio Dubon from the Brewers, OF Joseph McCarthy from the Rays, RHPs Daniel Winkler and Tristan Beck from the Braves and OF Jaylin Davis, RHPs Prelander Berroa and Kai-Wei Teng from the Twins.
Phillies: Acquired OF Corey Dickerson from the Pirates for a player to be named and $250,000 in international signing money, and RHP Dan Straily from Baltimore for cash. Straily was assigned him to Triple-A. Dickerson is hitting .317 this season.
Phillies: RHP David Robertson said he needs season-ending surgery to repair a flexor strain and he's getting a second opinion to determine if he needs Tommy John surgery for the ulnar collateral ligament in his elbow.
RHP Dereck Rodriguez (4-5, 4.99 ERA) starts for the Giants, and Jake Arrieta (8-8, 4.51) goes for the Phillies in the series finale Thursday.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP—Sports