Gray (4-2) allowed two runs and four hits. The right-hander also struck out eight and walked two while improving to 4-0 in five home starts.
''I just feel comfortable here,'' Gray said. ''It's home for me and I know I can outpitch the other guy.''
Daniel Bard worked a shaky ninth for his third save in five opportunities. The Giants scored an unearned run on catcher Dom Nunez's throwing error, but Darin Ruf bounced to shortstop with a runner on third for the final out.
''The ninth inning wasn't the prettiest but we got it done,'' manager Bud Black said. ''A win's a win. Daniel showed a little mettle after the two walks. The resiliency of the group showed. Guys were ready to play today and Jon did a great job.''
The start of the game was delayed 1 hour, 25 minutes, due to inclement weather.
San Francisco catcher Buster Posey left in the fifth with a tight right hamstring, manager Gabe Kapler said. Posey was thrown out trying to stretch a single into a double to end the top of the inning.
''His whole lower half has been tight so we wanted to ensure we didn't put him at risk, so we got him out of there,'' Kapler said. ''I'm optimistic Buster will be fine and be in the lineup on Friday.''
Brandon Crawford continued his hot hitting against the Rockies with a two-run homer in the second inning. Crawford is 10 for 23 with four homers, six walks and 10 RBIs in eight games against Colorado this season.
''Been able to square balls up recently and when you square balls up in Colorado they typically seem to go a long way,'' Crawford said. ''I feel good at the plate, I've been able to lay off pitches I was swinging at early on.''
Giants starter Logan Webb retired his first 10 batters, but the Rockies got to him the second time through the lineup.
Charlie Blackmon hit a tying two-run single in the fourth. A walk loaded the bases and Alan Trejo got his first major league RBI with a four-pitch walk, ending Webb's afternoon.
''The last one was tough,'' Webb said of the walk to Trejo.
Gray greeted Matt Wisler with an RBI single, and Raimel Tapia made it 6-2 with a two-run single.
Webb (1-3) struck out five and walked three in 3 2/3 innings.
Ruf hit a two-run homer in the seventh to pull San Francisco within two runs.
Giants: Kapler said RHP Kevin Gausman (COVID-19 injured list) and RHP Johnny Cueto (lat) will start Saturday and Sunday, respectively, against San Diego. ... OF Mike Yastrzemski (left oblique strain) will return this weekend, but Kapler didn't say exactly when.
Rockies: INF Brendan Rodgers (left hamstring strain), LHP Kyle Freeland (left shoulder strain) and RHP Yency Almonte (hand) will accompany the team to St. Louis. Freeland and Rodgers will take part in a simulated game, Black said, and if things progress well they will go out on rehab assignments.
SHOWN THE DOOR
San Francisco was frustrated by umpire Tony Randazzo's strike zone, and it boiled over a bit when Curt Casali fanned on a check swing for the first out of the ninth. Pitcher Alex Wood was ejected for yelling from the dugout after the strikeout.
''We had a frustrated dugout,'' Kapler said. ''There was some moments of frustration for both our hitters, for Logan, for Buster and ultimately for Curt. Baseball's hard for everyone and after a game like this it can be frustrating to think back to some of the moments where the calls didn't go your way.''
ON THE MOVE
San Francisco traded outfielder Skye Bolt to the Oakland Athletics for cash. The Giants claimed Bolt off waivers after he was designated for assignment by Oakland on April 1. He appeared in two games for San Francisco and struck out in his only plate appearance.
The Giants optioned catcher Joey Bart to Triple-A after the game.
Giants: RHP Anthony DeSclafani (2-1, 2.00 ERA) will open a three-game series against San Diego on Friday night.
Rockies: LHP Austin Gomber (2-3, 5.90 ERA) will face his former team in the opener of a three-game series in St. Louis. Gomber was one of the players included in the trade that sent Nolan Arenado to the Cardinals.
Copyright 2021 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.