SAN DIEGO -- All-Star closer Heath Bell was working on a franchise-record stretch of 99 games and 102 at-bats without allowing a home run when he made one costly mistake on an 0-2 pitch.
Aubrey Huff led off the ninth inning with a tying drive into the right-field seats, and the San Francisco Giants went on to a 6-2 victory over the struggling San Diego Padres in 12 innings on Thursday night.
Mike Fontenot brought in the go-ahead run with a bases-loaded walk with two outs in the 12th, and the NL West-leading Giants piled it on against the last-place Padres.
The bullpen collapse extended the Padres' losing streak to six games, tying their season high.
Bell was trying to preserve a 1-0 win for Aaron Harang, who threw seven strong innings in his second start back from a stint on the disabled list, but Huff hit his ninth homer.
"Huge for us. We're looking at a 1-0 loss there," Giants manager Bruce Bochy said. "We needed something like that to save us and he did with the home run."
Until Huff's shot, Bell hadn't given up a homer since San Francisco's Juan Uribe went deep on April 19, 2010.
"I didn't know until someone told me it was last year against these guys and then I remembered it was Uribe," Bell said. "He tattooed one to left field.
"I threw a breaking ball inside, and then I tried to go down and in," Bell said. "It was a pretty good pitch but I think Huff was maybe expecting it. He saw it real well and he just lifted it up. That's why he's good. He can just kind of throw his bat down there and flip it out of here. As soon as I saw him hit it, I knew it was going to go 10 to 15 rows deep."
It was Bell's second blown save in 62 chances dating to last year and second in 28 opportunities this year.
"That's a big hit right there, off one of the best closers in the game," Giants starter Madison Bumgarner said. "To put us back in the game right there, that was a big-time hit."
Giants All-Star closer Brian Wilson came on with the bases loaded and one out in the bottom of the 12th for his 27th save in 31 chances. He allowed Will Venable's sacrifice fly, then walked Chris Denorfia to load the bases before getting Jason Bartlett to ground out.
Cody Ross started the winning rally in the five-run 12th with a leadoff walk against Luke Gregerson (2-3) and was replaced by Emmanuel Burriss, who stole second. Gregerson then walked Brandon Crawford and committed an error trying to field Eli Whiteside's bunt, loading the bases. Miguel Tejada fouled out and Andres Torres struck out before Fontenot walked on four straight pitches.
Santiago Casillas (2-1) threw two perfect innings for the win.
The Padres, the lowest-scoring team in the NL, dropped 13 games behind the defending World Series champions and 13 games under .500.
The Padres had scored only two runs in their last 44 innings before the All-Star break. Their losing streak includes consecutive shutouts at Los Angeles, including a game in which the Dodgers didn't get their first hit until there were two outs in the ninth inning.
Harang held the Giants to five hits while striking out four and walking one. In his previous start, Harang handed a no-hit bid to the bullpen after six innings before the Dodgers won 1-0 after getting two hits with two outs in the ninth.
Whiteside tied his career high with three hits.
The Padres had three consecutive hits off Bumgarner for a run with two outs in the third. Denorfia singled to right, advanced on Jason Bartlett's base hit to center and scored on Chase Headley's single to left.
Bumgarner allowed seven hits in six innings, struck out four and walked none.
San Diego State football coach Rocky Long threw out the ceremonial first pitch, to Padres manager Bud Black, an SDSU alum. ... The Padres wore 1983 throwback brown uniforms as a tribute to Hall of Fame manager Dick Williams, who died July 7. There was also a video tribute and a moment of silence. Williams managed the Padres from 1982-85, including reaching the World Series for the first time in franchise history in 1984. Williams managed the Oakland Athletics to back-to-back World Series titles and also led the Boston Red Sox to the 1967 World Series. ... Headley left in the eighth with a bruised left ankle.