PHOENIX -- Justin Upton's 10th-inning homer gave the D-backs a win Thursday night, and it also exorcised some demons in the process.With the 3-2 victory, the D-backs ended a five-game losing streak at the hands of the first-place Giants, who have owned Arizona, having won 10 of 11 games before Thursday. The second-place D-backs trail San Francisco by 1 1/2 games in the National League West. "Obviously, you don't ever want to give a team momentum," Upton said. "They felt like they could sweep us and we were resilient enough not to let them. I feel like we've battled and they've come out on top however many times we've played them, so to finally win that close game and kind of break that little stretch is good." The D-backs almost let this one slip away when the Giants rallied to tie the game on Pat Burrell's sacrifice fly with one out in the ninth off closer J.J. Putz, who blew his third save in 21 opportunities. That cost Arizona starter Ian Kennedy a much-deserved win. The right-hander allowed just one unearned run over eight innings and struck out 10 while walking just one. "He pitched unbelievable, and everyone knows that," Upton said. "As long as Ian gives us a chance to win, we'll win the games he pitches." The night started off on a frustrating note for Chris Young, who was hit on the forearm by a pitch from Ryan Vogelsong in the second inning. Home-plate umpire Kerwin Danley ruled that the ball was fouled off Young's bat, and he wound up flying out. Young's fortunes turned in his second at-bat in the fourth, when he hit a 1-2 curve from Vogelsong into the bullpen in left to score Upton and give the D-backs a 2-0 lead. "Vogelsong did a good job tonight," Young said. "He's a good pitcher, and being the first time I faced him, you really don't know what kind of plan to have because all you have to go by is video. His fastball was working well tonight, he had a pretty good sink on it. The curveball, I saw it better than the heater. That at-bat before, he had thrown me about 10 to 12 heaters and I couldn't seem to get the barrel on it, so the curveball up in the zone was definitely a better option for me." The Giants' cut the lead to 2-1 in the fifth, when, with runners on first and second, Kennedy struck out Eli Whiteside for the second out of the inning. The runners were stealing on the play and catcher Miguel Montero's throw to third was off the mark and got away from third baseman Ryan Roberts, which allowed Cody Ross to come home. It was mistakes like that, along with an 0-for-5 performance with runners in scoring position that tempered D-backs manager Kirk Gibson's enthusiasm about the win. "I'm just talking about the fundamentals," Gibson said. "Trust me, everybody's busting it, but it's unacceptable. Our approach with runners in scoring position is not even close to what it needs to be. [The Giants] have good pitching, but we have to change the way we approach those situations if we expect to be successful for the full season. We didn't play good, but we won the game. We need to play a lot better. You get frustrated with things like that, but we hung in there and J-Up picked us all up. J-Up and C.Y. had a great game again." Pablo Sandoval led off the ninth for the Giants with a ground-ball single up the middle and moved to third when Aubrey Huff followed with a high chopper over the head of Juan Miranda at first. Putz got Ross to strike out, but Burrell hit a liner to left for a sacrifice that scored Sandoval and tied the game. That's how things remained until Upton connected on the first pitch he saw in the 10th from Santiago Casilla (0-2). "You're living on the edge with a tie ballgame and there's a pretty good hitter up there that hit it well," Giants manager Bruce Bochy said of Upton, who is hitting at a .424 clip over his last eight games. The two teams face each other nine more times this year, six of which will be at AT&T Park in San Francisco, and the D-backs hope Thursday's win let the Giants know they intend to be a thorn in the defending champs side all year long. "They've been tough on us this year, and it is what is," Young said. "We've played close games, but they always had the upper hand by a little bit, so as a team, it's always nice to get that win. We play those guys quite a few more times this season, and it's nice to put it in their head that we can win those close games, too."