SAN FRANCISCO (AP) -- Tim Lincecum's first loss of the year came via a debated balk call that pushed home the go-ahead run.
For the Colorado Rockies, it hardly mattered how they won considering the team was short-handed and forced to juggle its infield because of injuries.
"That's one of the biggest victories I've enjoyed during the regular season," Rockies manager Clint Hurdle said. "It just goes to show when you think you have control, what do you control? At the end of the day, you really don't."
Iannetta also hit the first home run off Lincecum this year with a second-inning solo shot to help Aaron Cook (4-1) win his fourth straight start. Iannetta doubled to start the seventh.
Giants manager Bruce Bochy was ejected for arguing the balk, a night after Hurdle was thrown out for the same thing.
"I still don't understand it," Bochy said. "It's obviously huge. It's a tough one to lose."
With Iannetta at third base with one out in the seventh inning, Giants catcher Bengie Molina appeared to ask for a timeout with Yorvit Torrealba at the plate. But plate umpire Gary Darling called a balk on Lincecum to score Iannetta for the go-ahead run and a 3-2 Rockies lead.
Bochy rushed out and argued heatedly for several minutes before Darling threw him out, the second ejection of the season for Bochy and the 35th of his career.
"He started, stopped, then Bengie tried to cover for him by calling the timeout," Darling said. "Whether he didn't have the sign or not, I don't know about that, what was going on there."
Lincecum (4-1) allowed Iannetta's solo home run and an RBI double to Garrett Atkins, but was efficient and got many quick outs the rest of the way. He was tagged for season highs of eight hits and three earned runs, matched his season low with four strikeouts and walked one.
Lincecum hadn't been in such a situation before, losing like that.
"It's unfortunate, but I've seen other games where that's happened, too," Lincecum said. "It's part of the game."
Atkins' double extended his majors-best hitting streak to 14 games.
Atkins made his major league debut at second and Iannetta did the same at third because of injuries to Jeff Baker and Tulowitzki. Baker was scratched due to a broken blood vessel in his right middle finger that happened during pregame warmups. Tulowitzki, who replaced Baker in the lineup, left after bending over to try to stop Aaron Rowand's single in the first. Tulowitzki grimaced and grabbed his left hip and lower back area. He then walked gingerly off the field.
The Rockies' athletic trainer first checked on Tulowitzki after he threw to first base on Eugenio Velez's grounder that was dropped for an error, three batters earlier.
Hurdle had to get creative to have a healthy infield, only a few days after Colorado designated infielder Jayson Nix for assignment.
Clint Barmes moved from second to shortstop. Atkins moved from third to second and Iannetta, a backup catcher, entered the game to play third.
Iannetta then homered leading off the second to tie the game at 2.
Atkins made a run-saving play with two outs and a runner on third in the sixth, ranging far to his left to nab a grounder hit by Brian Bocock.
"It's a good win, no doubt about it," Colorado's Todd Helton said. "It's a cruel and unusual game sometimes. It's definitely humbling. But it also was a fun win."
Lincecum, who also had his third hit in his first eight at-bats with a second-inning single, had allowed only four earned runs over his initial five starts. He pitched well a night after the Giants captured a 4-0 win to earn starter Matt Cain his first victory after a 10-start winless stretch.
Fans flashed orange "K" strikeout cards each time Lincecum fanned a Colorado batter.
Cook didn't allow an earned run and gave up 10 hits in seven innings. He struck out three and walked two.
Taylor Buchholz pitched a perfect eighth and Brian Fuentes finished for his second save in four chances. The Giants got the tying run aboard when Jose Castillo drew a leadoff walk, then he advanced on Bocock's sacrifice. But Randy Winn popped up on a 3-0 pitch and Fuentes struck out pinch-hitter Dan Ortmeier to end it.
Colorado picked up its 100th win all-time against San Francisco. ... Lincecum hadn't given up a homer in eight starts since Ryan Braun of Milwaukee connected last Aug. 26. ... Fuentes is unscored upon in 13 of 14 appearances this year and has never blown a save against San Francisco in 15 tries.