Giants reliever Jeremy Affeldt (1-4) was just two strikes away from forcing extra innings when a two-seam fastball fell outside the zone and gave Rockies slugger Todd Helton a free path to first. Josh Rutledge took over for Helton as a pinch-runner and stole second before rookie Nolan Arenado swung on a 2-2 count.
"He's a great pitcher, but he hung a splitter and I just put a good swing on it," Arenado said.
As the ball sliced into center to drive in the winning run, Arenado tossed his helmet with the widest of smiles as his teammates mobbed him. Affeldt was already on his way to the dugout as Rutledge slid home.
"Two-out walks are going to kill you, and that's what it did," Affeldt said.
"A few outings now where I've had two outs and I've gotten beat, we've lost the game. It's just frustrating to get two outs, don't get the job done."
Cain tossed one of his best games this year, allowing three hits, striking out five and walking one and retiring the final 20 batters he faced. Cain said there was some talk about coming back for the ninth after throwing 105 pitches, but with two of the three upcoming batters left-handed, Affeldt appeared the more logical choice.
"It was set up perfect for Jeremy," Giants manager Bruce Bochy said. "[Cain] did his job."
San Francisco's offense collected just three hits -- all singles -- through the first five innings, continuing the Giants' extensive offensive slump. A Posey double in the sixth plated the Giants' first run to knot the game at 1, but they never scored again and have only three runs in their last 27 innings.
Posey's ball into deep left-center scored Marco Scutaro, who reached on a single. Posey's homer was the Giants' lone run in Friday night's loss, and he has now reached base safely in 47 straight starts against Colorado.
San Francisco's losing streak moved to a season-high six games, and the Giants have dropped eight of nine.
The first batter Cain faced, Corey Dickerson, doubled into right before the Giants right-hander made one of his only mistakes of the afternoon -- an 0-2 curveball to Michael Cuddyer that stayed over the middle of the plate.
Cuddyer turned Cain's mistake into an RBI single, extending his hitting streak to 26 games, a franchise record and the longest in the Majors this year.
"I wasn't getting ahead of guys a little bit early, but I had a chance to get out of that in the first inning and I didn't," Cain said. "I didn't make a good pitch to Cuddyer, and obviously as hot as he is, you make a mistake to him, he's going to get a hit."
The Giants nearly placed themselves in a two-run hole in the second when a pair of defensive miscues placed runners on second and third with one out. Rockies catcher Yorvit Torrealba kicked off the inning with a double and starter Jorge De La Rosa laid down a bunt along the third-base line.
But Pablo Sandoval's throw to second was off the mark, and when center fielder Juan Perez picked it up and tried to beat Torrealba to third, the throw careened off the dugout fence, allowing De La Rosa to make it to second. A mental slip-up by the pitcher saved the Giants, as he immediately took off for third on a slow grounder and trapped Torrealba in a rundown between third and home.
"[Cain] was great," Bochy said. "He saved us in that second inning. We were throwing the ball all over the place and he picked the club up at that point and kept them from scoring again."
De La Rosa worked through six innings without running into serious trouble, striking out four and allowing a run and six hits. After a brief examination on the mound, the Rockies pulled him before the start of the seventh due to bruised left thumb that has plagued him over his last three starts.
Four Rockies relievers combined for three scoreless innings to preserve the tie. Rafael Betancourt (2-3), in his first appearance since returning from the DL, got the win after a scoreless ninth.
Bochy and his players did not hide their frustration in a subdued postgame clubhouse, but they remain confident they have the pieces to make a run at the division crown. They aren't waiting for the help that could come before the looming Trade Deadline, carrying the blame on their own shoulders.
"We're in a funk right now and we're the only ones that can really get our way out of it," Cain said. "That's really all that it is."