"It wasn't going to be easy in the first place, but we're not out of it yet," D-backs outfielder Jason Kubel said.
The win snapped the Rockies' nine-game losing streak.
Trevor Cahill (12-12) turned in a solid outing, but he did himself no favors in the first inning.
After retiring the leadoff hitter in the inning, Cahill hit Charlie Blackmon with a pitch and when Jordan Pacheco followed with a grounder back to the mound, Cahill threw wildly to second base for an error.
Blackmon scored one batter later when Tyler Colvin singled to right.
"I could have turned the double play," Cahill said. "I didn't see it off the bat real well and then tried to rush it and threw it away. He hit it and it was a chopper. I thought I might have to go back on it and then came in on it and then just tried to rush it to second."
The D-backs briefly took a 2-1 lead in the fourth when Paul Goldschmidt drew a two-out walk and Kubel followed with his 30th homer of the season.
"I just got a changeup just left out over the plate and fortunately for me that was my bat speed tonight and I hit it so it worked out from that aspect," Kubel said.
That was the only damage that Rockies starter Tyler Chatwood (5-5) allowed in his 5 2/3 innings of work.
"He was throwing hard first of all and keeping it somewhat elevated some of the time, but not all the time," Kubel said. "It makes it kind of hard to catch up to it. After that first round, he started going to more breaking stuff and kind of kept us a little off balance. He did a nice job tonight."
Other than Kubel's homer, the only other hits Chatwood allowed were a single to Miguel Montero in the second and a single to Goldschmidt in the sixth.
"The thing that was so impressive tonight was the way that [Chatwood] pounded the ball into the strike zone, and pounded it at 94, 95 mph, down in the strike zone, and did it the entire time he was out there," Rockies manager Jim Tracy said. "His ball-strike ratio was terrific [86 pitches, 52 strikes], which is why he got as far into the game as he got."
The Rockies responded after Kubel's homer with two runs in the bottom half of the inning thanks to RBIs by Andrew Brown and DJ LeMahieu to take a 3-2 lead.
Colorado added an insurance run in the eighth when Brown hit his fourth homer of the year.
Cahill allowed three runs, two earned, on nine hits in six innings.
"They were aggressive," he said. "After I think the second inning I talked to [Montero] and said they're kind of looking for a first-pitch sinker or whatever and we started mixing it up a little bit. It's tough because I felt like I couldn't throw my off-speed stuff for a strike early in the count so we kind of went back to the heater and just tried to be a little bit more fine."
The D-backs collected back-to-back singles off closer Rafael Betancourt with two outs in the ninth, but John McDonald flied out to end the game.
"We had an opportunity, our best opportunity, late in the game in the ninth inning against Betancourt and it just didn't work out," Gibson said.