Gray (9-7) has won his last four decisions, and the Rockies have won the last five games he's started. That includes three straight victories since a brief demotion to Triple-A to clear the young right-hander's head.
Gray struck out five over 7 1/3 innings, helping Colorado finish the month 17-6. Gray allowed three runs, two earned, with four hits and two walks.
"I'm definitely feeling more competitive than I ever have before which is good," Gray said. "That's one thing I want to feel all the time out there is competitive and ask myself, `How good can you be today?' and just go with that.
"Just making the game fun and playing the small games within a game has been carrying me through."
Manager Bud Black liked what he saw.
"He probably threw a few more true curveballs tonight than the previous couple outings," Black said. "It was working well. The change of velocity from the curveball to the fastball I think was a great variable for Jon."
Wade Davis got his 31st save in 35 opportunities with a 1-2-3 ninth inning. He saved a career-high 32 last year with the Cubs.
Colorado went ahead 2-1 on Blackmon's homer in the fifth. Ryan McMahon led off with a 12-pitch walk, and with two outs, Blackmon hit a 1-2 pitch into the right field bleachers. Blackmon's homer extended his hitting streak to 13 games.
Matt Carpenter led off with a home run, sending an 0-2 pitch into the right field seats. It was Carpenter's seventh leadoff home run this season. It was the 22nd of his career, passing Hall of Famer Lou Brock on St. Louis' career list.
"To be in the same sentence with him (Brock) is pretty special," Carpenter said.
Carpenter, who hit an MLB-leading 11 homers in July, leads the Cardinals with 26.
The Cardinals scored two runs in the eighth, cutting the lead to 6-3. St. Louis loaded the bases with one out against Gray. Seung Hwan Oh gave up a sacrifice fly to Carpenter, and a passed ball and throwing error by catcher Tom Murphy allowed Dexter Fowler to score.
Flaherty (4-6) pitched 5 1/3 innings. It marked the first time in five starts he pitched into the sixth inning. He allowed four runs, five hits and two walks. He struck out seven.
Cardinals: St. Louis traded outfielder Tommy Pham and international bonus slot allotment to Tampa Bay for outfielder Justin Williams, left-hander Genesis Cabrera and right-hander Roel Ramirez. The 30-year-old Pham has been a member of the Cardinals organization since being drafted in 2006. He was batting .248 this season with 14 home runs and 41 RBI. St. Louis also acquired minor league outfielders Conner Capel and Jhon Torres from the Cleveland Indians in exchange for Triple-A outfielder Oscar Mercado.
Rockies: RHP Chad Bettis (middle finger blister) will make another rehab start Thursday for Triple-A Albuquerque. If he does well with no problems, he could return to the big club as either a starter or a reliever. Bettis hasn't pitched in the major league since July 1.
Cardinals: RHP Carlos Martinez (right shoulder strain) was placed on the 10-day disabled list on Tuesday and had an MRI. President of baseball operations John Moseliak said the team does not believe the injury is season-ending, and Martinez will be able to pitch again. ... 2B Kolton Wong (left knee inflammation) is eligible to come off the DL on Wednesday but likely will be activated Thursday or Friday. ... St. Louis recalled rookie outfielder Tyler O'Neill and left-handed reliever Tyler Webb from Triple-A Memphis on Tuesday.
Rockies: Kyle Freeland (9-6, 3.13) will be making his first start in St. Louis and second against the Cardinals. He pitched six innings in taking a loss in a 3-0 defeat to St. Louis on May 27, 2017. The Rockies have won each of his last five starts.
Cardinals: RHP Luke Weaver (6-9, 4.70) will make his second career appearance against Colorado. He pitched a career-low two innings in his start in 2016 against the Rockies in an 11-1 loss. In his most recent outing, Weaver pitched six innings and picked up the win in a 5-2 victory over the Cubs.
More AP baseball: https://apnews.com/tag/MLBbaseball
Athletics' Bob Melvin nabs AL Manager of the Year honors
Oakland Athletics skipper Bob Melvin was named American League Manager of the Year on Tuesday after guiding the team with the lowest Opening Day payroll in baseball to a 97-65 record and its first playoff berth in four years.
Brian Snitker is NL's top manager after leading Braves to East title
After leading the Braves to an unexpected NL East title, Brian Snitker has been named the NL manager of the year.
Did Ohtani deserve Rookie of the Year?
Around the Horn discuss whether Shohei Ohtani deserved Rookie of the Year even though he only played 104 games this season.
MLB to investigate claims of racial discrimination vs. Mariners
MLB said in a statement provided to The Athletic that it will investigate allegations of racial discrimination in the Seattle Mariners organization made by a former employee.
Time for Giants to decide what to do with Madison Bumgarner
Forget nostalgia. With Farhan Zaidi taking over the front office, San Francisco must re-evaluate how the hero of Octobers past fits into the franchise's future.
Phillies manager Gabe Kapler loses Malibu home in Woolsey Fire
Phillies manager Gabe Kapler is thankful his family is safe after his Malibu home was destroyed in the Woolsey Fire that has burned at least 435 buildings and is threatening tens of thousands more.