PHOENIX -- Tim Locastro has been hit by pitches 12 times in 102 plate appearances this season. Avoiding it with the bases loaded on Sunday still worked in his favor.
Locastro's single in the 10th inning gave the Arizona Diamondbacks a 3-2 win over the San Francisco Giants, a line drive to left field that scored Nick Ahmed and helped the Diamondbacks end a season-long six-game losing streak.
The first pitch of Locastro's at-bat in the 10th against Giants reliever Mark Melancon almost hit him. Locastro turned out of the way.
"We would have won either way but I wanted to get a hit there," Locastro said. "I wasn't exactly trying to get away but it happened to miss me."
Melancon (3-2) uncorked a wild pitch to put runners at second and third with one out, and Carson Kelly was intentionally walked to bring up Locastro.
"Actually with that pitch not hitting me, I sort of knew his approach was to come in a little bit," Locastro said, "so I was looking in there and I was able to fight it over the third baseman's head and drop it in for a single."
Matt Andriese (4-4) pitched a scoreless top of the 10th to earn the win. He was the last of four relievers that held the Giants hitless for four innings.
"I have come in here for five straight days talking about losing a baseball game, and that's hard," Diamondbacks manager Torey Lovullo said afterward. "It's hard for me. It's hard for the team. It's hard for everybody, but we've got to find a way to keep grinding to have these (winning) moments happen."
Christian Walker had three hits for Arizona, extending his hitting streak to a career high eight games.
Kevin Pillar homered for the Giants, his 10th of the season, but San Francisco was held to four hits for the game.
"We just couldn't get anything going with the bats," Giants manager Bruce Bochy said. "They got the big hit, we didn't. That's the difference in the game."
Locastro rolled a single into shallow right field, the Diamondbacks' first hit of the game, driving in Caleb Joseph with two outs in the third inning. The Giants tied the score at 1 on Stephen Vogt's ground out to score Evan Longoria from third base in the top of the fourth.
Arizona went back in front 2-1 with Walker's RBI single in the fourth, the result of a nine-pitch at-bat that drove in Adam Jones, who'd reached on a wild pitch third strike.
Pillar led off the seventh inning with a solo shot to left field, which spelled the end of Diamondbacks starter Merrill Kelly's day. Kelly went six innings and allowed two runs on four hits, striking out nine.
The Diamondbacks opened their half of the seventh with back-to-back hits off Giants starter Shaun Anderson to put runners on second and third, and the Giants turned to Reyes Moronta in relief. Moronta worked out of the jam without allowing a hit.
Anderson allowed two runs on five hits in six innings.
"I just stayed with the same game plan. I attacked them early and got some quick outs," Anderson said. "Our bullpen has been absolutely dominant all year. I don't think they get enough credit for what they do."
The Diamondbacks were primed to take the lead in the seventh with Ahmed up to bat and runners in scoring position with no outs. Moronta threw a pitch to the backstop, but the carom arrived cleanly to catcher Vogt's glove, and Vogt had plenty of time to tag out Eduardo Escobar trying to score from third base.
The Diamondbacks failed to score in the inning.
Giants: Vogt took a foul ball of his right knee in the bottom of the fifth inning and was limping badly for a few moments immediately afterward, but remained in the game. After the game his knee was heavily wrapped. "I'm sure he's going to be sore tomorrow," Bochy said of Vogt.
Diamondbacks: 2B-OF Ketel Marte was held out of the lineup for a second straight day due to a minor groin injury from Friday's game.
Diamondbacks: RHP Zack Greinke (8-3, 2.91) is tabbed for the opener of a three-game series against the Los Angeles Dodgers starting Monday. He could face the Dodgers' Clayton Kershaw, a former teammate and fellow Cy Young Award winner, for the second time in his career.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Kenley Jansen says Astros' cheating worse than steroids, gambling
Dodgers closer Kenley Jansen said Saturday that he considers the Astros' using technology to steal signs worse than players' using steroids or betting on baseball. Jansen didn't have much use for their apologies, either.
Neighbors Athletics, Giants make first trade since 1990
In a move to add experience to their bullpen, the A's got right-hander Burch Smith from the Giants for cash. It is the first trade between the neighboring teams since Dec. 4, 1990.
Astros cheating scandal: MLB players weigh in on sign stealing
Players across the game weigh in on responsibility, whistle-blowing and punishing cheating in baseball.
Two California Little Leagues ban use of Astros
The Long Beach Little League and the East Fullerton Little League have both banned the use of "Astros" from their teams this year after the major league team was found to have illegally stolen signs en route to winning the 2017 World Series.
Correa claps back at Bellinger, Altuve critics
Carlos Correa says that Jose Altuve did not want to use the sign-stealing scandal and vehemently denies Altuve and the Astros used buzzers.
Kris Bryant trying to tune out trade rumors
Kris Bryant explains what he's done to ignore the trade rumors that have been surrounding him.