PHOENIX (AP) -- Carlos Gonzalez, heating up for the stretch run after a subpar season at the plate, homered twice and the Colorado Rockies won their sixth game in a row, beating the Arizona Diamondbacks 4-2 on Tuesday night to tighten the race for the National League's top wild card.
Gonzalez drove in all four Colorado runs in his first multihomer game since Aug. 16 last year and is batting .451 (14 for 31) in September.
Jon Gray (8-4) gave up two runs and scattered seven hits over seven solid innings, striking out 10 with no walks and a hit batter for the Rockies, who won their eighth straight road game to pull within three games of Arizona for the first NL wild card.
Gray matched the season high for strikeouts he set in a win at Arizona on June 30. Chris Rusin got two outs for his second save.
J.D. Martinez homered for the 22nd time in 47 games with the Diamondbacks and just missed another with a double off the top of the right-field fence leading off the ninth. He was stranded at third when Ketel Marte grounded out to end the game.
Martinez's 38 home runs overall this season tied his career high.
Gonzalez's two homers - one off starter Taijuan Walker, the other off reliever David Hernandez - hit almost the same spot off the wall above the swimming pool in right field. Hernandez (2-1) pitched two-thirds of an inning and took the loss.
The Diamondbacks have lost two straight to Colorado halfway through a four-game series and have dropped four of their last five, all at home, after a 13-game winning streak. The Rockies' eight-game road winning streak matches their second-longest in club history.
The game was tied at 2 through six and lefty Andrew Chafin got Charlie Blackmon to fly out to start the seventh. Hernandez came on and DJ LeMahieu beat the extreme shift Arizona puts on against him with a rare single to left.
Gonzalez followed with his second two-run homer and Colorado led 4-2.
Arizona scored first when Martinez hit Gray's pitch off the edge of the batter's eye, an estimated 447 feet, leading off the second.
The Rockies countered in the third when Blackmon drew a leadoff walk from Walker, and Gonzalez sent Walker's 1-0 pitch to right.
Arizona loaded the bases with no outs in the third but only scored one run on Jake Lamb's sacrifice fly to deep left. Paul Goldschmidt, who is 0 for 8 in the last two games, lined into a double play to end the inning.
Diamondbacks: Arizona manager Torey Lovullo confirmed that RHP Randall Delgado has a flexor strain in his throwing elbow. The injury occurred during Delgado's rehab stint. He has been moved to the 60-day DL.
The Diamondbacks send left-hander Patrick Corbin (13-12, 4.16 ERA) to the mound and the Rockies counter with right-hander German Marquez (10-6, 4.27) in the third game of the four-game series Wednesday night.