The win enabled the Giants to avoid getting swept in their three-game series and sent them home with just their second win in the past seven games.
The Giants finally showed some offensive life, hitting six homers -- Michael Morse also homered twice -- but they had to overcome an early four-run deficit as starter Matt Cain was trying to find his footing.
"I couldn't be prouder of these guys," said Giants manager Bruce Bochy, who was ejected by home-plate umpire Chris Conroy in the fourth for arguing a called third strike. "We're down, what, 5-1, looking at getting swept here and how hard they fought to find a way to win a game here. It makes for a better flight home and a day off."
Sanchez came into the game 3-for-25 with two doubles and three RBIs this season and six career homers in 403 at-bats. He came up in the 11th against Chad Bettis, who threw just 19 of 34 pitches for strikes that inning and said, "I put myself in a bad spot, and I got hurt for it."
After Hunter Pence singled off Bettis to open the 11th, Brandon Belt walked. Following Juan Perez's sacrifice bunt, Bettis intentionally walked Joaquin Arias to load the bases for Sanchez, who fouled off two 3-2 pitches before launching Bettis' 10th pitch of the at-bat over the wall in center.
"Bases loaded, I never thought he would throw me another pitch except the fastball," Sanchez said. "I just tried to hit it to the outfield, stay to the middle of the field, and I hit it well."
The Rockies outhit the Giants 16-14 and belted three homers, the last of which made matters interesting in the 11th. Closer Sergio Romo gave up a leadoff single in that inning to Troy Tulowitzki, and Justin Morneau followed with a two-run homer. With one out, center fielder Drew Stubbs singled past Arias at third. But Romo got right fielder Brandon Barnes to ground into a double play to end the game that lasted four hours, 26 minutes.
The Giants last hit six homers in a game Sept. 4 at San Diego. Sanchez and Morse became the first two Giants to homer twice in a game since May 25, 2005, when Moises Alou and Pedro Feliz accomplished the feat against the Los Angeles Dodgers. Sanchez's grand slam was the sixth in extra innings by a Giant in the San Francisco era, dating back to 1958. The last player to do that was A.J. Pierzynski in 2004 against the Montreal Expos in Puerto Rico.
"It's a lot of feeling in that situation," Sanchez said, "because everybody wants to be the hero. In this field the ball flies. I hit it well, and right at the moment that I hit it, I knew that was out of the park."
The Giants took their first lead when Belt hit a two-run homer in the seventh that put them ahead, 7-6. The homer came against left-hander Rex Brothers, who had walked Pence ahead of Belt.
But the Rockies tied the score in the bottom of the inning and could have had more had reliever Jeremy Affeldt not snuffed out a rally with the bases loaded. He relieved Cain, who settled down after allowing five runs in the first two innings, with none out and runners on first and second and the score tied at 7 on a double by Nolan Arenado, who extended his career-high hitting streak to 14 games. Affeldt struck out Morneau and Wilin Rosario and walked Stubbs but grabbed Barnes' hard bouncer to end the inning.
In the eighth, Sanchez homered on the first pitch from Matt Belisle, who had just entered the game, to give the Giants a short-lived 8-7 lead. Santiago Casilla took the mound in the bottom of that inning and gave up a leadoff single to DJ LeMahieu. He was sacrificed to second and took third when third-base umpire Bob Davidson called a balk on Casilla. With the infield in, second baseman Brandon Hicks, who had a career-high three hits, including a homer in the third, backhanded Charlie Blackmon's grounder but dropped it, taking away any play at the plate as LeMahieu scored to tie the game at 8.
Blackmon hit his fifth home run to put the Rockies ahead, 6-5, in the fourth. Morse homered on each of his first two-bats, hitting a three-run shot in the third that tied the game at 5 and gave him five homers this season. It was his seventh multi-homer game and first since April 2, 2013, while playing for the Mariners.
The Giants went 2-for-12 with runners in scoring position -- finishing 3-for-31 in the series -- but the two hits were Sanchez's grand slam and Morse's three-run blast. Bochy said the latter was the key hit that got the Giants' offense going after they scored three runs in the first two games of this series and 12 runs in their past seven games.
"Something's going to spark, something's going to ignite us," Morse said. "Today I think was that day. Hopefully, we take this win and keep it going. We got a good off day tomorrow [to] rest."