The win was the team's fourth in a row after losing the previous five.
Much like earlier in the week, when the Padres' Jake Peavy struck out 16 but Arizona was still able to win the game against the bullpen, the D-backs capitalized when Cain was removed after throwing 99 pitches.
"Anytime a guy's pitching that well and dominating like that, you get a little bit of a lift [when he comes out]," said manager Bob Melvin. "I can see why they did it. He's at 100 pitches, and they left him out there for a bunch last time. I can understand that."
Cain carried a no-hitter into the fifth and exited allowing just one run on one hit and four walks.
"Early on, it didn't look like he had as good as stuff as last time, but certainly the results were there," said Melvin. "It seemed like in the middle innings, we seemed to work him more and put some pitches on him to where we could get him out of the game earlier."
Lefty Jack Taschner came on to relieve to start the seventh with a 4-1 lead and put two runners on with one out. He then gave up a slow-rolling RBI single to Miguel Montero that squeaked into the outfield past the dives of first baseman Ryan Klesko and second baseman Rich Aurilia.
That set the stage for Hairston, pinch-hitting in the pitcher's spot.
The Giants countered with the righty Chulk (0-1), and Hairston promptly deposited Chulk's first offering, a poorly located fastball, an estimated 418 feet away deep into the left-field seats to give the D-backs a one-run cushion that would hold up.
"For a kid who is not used to that type of role where you come in and pinch-hit, it can be difficult," said Melvin. "He comes up there in a situation where there's no wiggle room, no time to ease your way into the at-bat. He's got to find something hard early in the count and go after it and he did."
"I just wanted to go up there and put a good swing on the ball," said Hairston of the first pinch-hit homer of his Major League career. "I was able to get a pitch that I could handle.
"I just told myself to be aggressive. Usually I take a pitch coming off the bench, but that hasn't been working, so I decided to switch it up and try something new, and it worked out."
The D-backs were down early in the game thanks partly to a change in strategy by Melvin. Whereas the manager walked Barry Bonds intentionally three times Friday night, all three times with a runner on second and first base open, he elected to pitch to him in the same situation in the first inning of this contest.
Bonds promptly hit his eighth homer of the season -- the 742nd of his career -- off starter Edgar Gonzalez to put the D-backs in an early hole.
"That's not my crowning moment right there," said Melvin. "At some point in time, especially early in the game, you maybe want to try and set a precedent that we're just not going to walk this guy every time. We're not scared to death of him, but the minute I thought that the ball leaves the ballpark, you want to crawl into a hole.
"It can demoralize the team to an extent because we had success [walking Bonds] yesterday. I felt that way, and you hate to affect the team that way, especially when the strategy worked so well the day before. It was the first inning, I tried to go against the grain a little bit, and it didn't work. I learned my lesson."
Gonzalez clearly did not have his best stuff or command on this day, but battled his way through five innings, allowing three earned runs and not letting the game get too out of hand.
The bullpen took it from there, holding the Giants scoreless for the rest of the game. Dustin Nippert (1-0) pitched two scoreless innings for the win. Doug Slaten and Tony Pena combined to work a scoreless eighth.
Jose Valverde had to dodge a couple of bullets, as a potential game-tying double by pinch-hitter Ray Durham missed the right-field foul line by a matter of inches, and he followed by taking a pitch deep to left-center that Chris Young had to track down by the 413-foot mark, but Valverde finished it off for his league-leading 10th save in 11 chances.