It seemed like it would be a storybook game for the D-backs -- at least through the first seven innings.
Wade Miley was dealing on the mound and showing pop in the batter's box, and the D-backs turned a late-inning lead over to the bullpen.
But it wasn't enough.
The Giants' rally started with a two-run homer by Buster Posey off David Hernandez in the eighth that tied the game at 4.
Hernandez's curve has been a real weapon for him this season, but it was not there for him Monday. After jumping ahead of Posey with a fastball, Hernandez missed with two straight breaking balls to fall behind 2-1.
"I got ahead 0-1 and I feel like if I even threw a curveball for a strike, it's just a different at-bat if I'm able to throw my off-speed for a strike," Hernandez said.
But he couldn't and Posey knew he couldn't, which meant he was sitting on the fastball that Hernandez threw next, and he blasted it over the wall in center.
Then in the ninth, Andres Torres led off with a single against Tony Sipp, and after Brandon Crawford sacrificed him to second, the Giants sent up Brandon Belt to pinch-hit.
Belt had just five hits in his 24 previous at-bats, but he got hold of a slider from Sipp and lined it into left-center for the game winner.
"Torres is a fastball hitter," D-backs manager Kirk Gibson said. "And Belt, he's been struggling, and we threw a ball out over the plate and he just [hit] it out there. Obviously not the way we wanted it."
It was the seventh straight win for the Giants at home.
"There's no quit in this team, I can tell you that," Giants starter Ryan Vogelsong said. "We fight to the last out. It's fun to watch."
It's a good thing for Vogelsong that the Giants do fight until the end, because otherwise he would have been tagged with the loss.
The D-backs jumped on Vogelsong in the first when former Giant Cody Ross drove home both a pair of runs with a bases-loaded single to right.
The runs snapped the Giants' scoreless-innings streak at 21.
The lead didn't last long, though, as the Giants tied things up in the bottom half of the inning.
Both starting pitchers settled in after that, with Miley retiring 11 straight at one point.
"Wade threw the ball well," Gibson said. "Everything was on target, but we couldn't finish it."
Miley even helped out offensively when he led off the fifth with a home run off Vogelsong to give Arizona a 3-2 lead. The homer was the first hit by a D-backs pitcher this season, snapping an 0-for-36 drought.
"I put a swing on it," Miley said. "I don't really remember it. It happened fast."
It was the first home run by a left-handed starting pitcher in AT&T Park history, and while Miley downplayed it after the game, fellow hurler Josh Collmenter said Miley told his teammates before the game that he was going to hit a homer.
But Miley, who said the last time he homered outside of batting practice was in an intrasquad game his freshman year of college, insisted that he was only kidding with his teammates and had no idea he would hit one.
"It was 2-0 and I was like, 'He's probably going to throw a fastball here,'" Miley said. "I'm a pitcher and I just cheated and I got lucky. I hit it on the sweet spot. It was like a blur. I swung and was like, 'Oh my God.' It feels good for anybody to hit a home run. I didn't really know what to do. I wanted to make sure I jogged around the bases fast enough. I wanted to get around there and get back into the dugout."
Eric Chavez added a solo shot in the sixth to increase the D-backs' lead to 4-2.
"We've got to find a way to close the door when we have the lead," Chavez said. "We put together really good at-bats late in innings like they did tonight. I think tonight you just tip your hat and try to come back and win one tomorrow."