Bonds hit his 724th career homer in the second inning, but left the game after he batted in the sixth due to an irritated left elbow.
The Giants have won three straight in the four-game series, and have beaten the Padres eight times in nine games since early July.
"We definitely could have folded up," Durham said. "The makeup of the ballclub, no matter what happens, we still battle until the last out's made. That showed tonight."
Durham singled with one out in the 13th, his third hit, and was sacrificed to second by pitcher Brad Hennessey, who pinch-hit because there were no bench players left. After Shea Hillenbrand walked, Alfonzo singled to left off Alan Embree (4-3) to score Durham.
Alfonzo stood on first and pumped his fist.
"It was my first time in that situation," he said. "I was so excited at that moment, that's why I put my hand up. Now I know I do my job."
After Embree's error loaded the bases, Scott Williamson came on and walked Pedro Feliz to force in another run.
"It's frustrating to go in, make quality pitches but cost us the game," Embree said.
Ben Johnson hit two homers for the Padres, including a tying shot in the 10th off Armando Benitez. Brian Giles and Mark Bellhorn also connected for San Diego, which lost for the seventh time in nine games, a slump that has dropped it from the NL West lead to third place.
The Padres are at .500 (60-60) for the first time since May 6.
"That's a tough one to lose," Padres manager Bruce Bochy said. "We got some big home runs there, we're close to winning the ballgame and they get some big two-out hits. That's the difference in the ballgame."
Steve Kline (3-3) pitched two innings for the win. Mike Stanton pitched the 13th for his second save in three chances.
Johnson homered to left leading off the 10th on a full-count pitch from Benitez, whose blown save was his fourth in his last six chances, and his eighth this season. Johnson had his first career two-homer game and tied his career high with three hits. He has four homers this year.
Durham had three RBI, including driving in Moises Alou with the tying run in the eighth and the go-ahead run in the 10th.
Alou doubled off Jon Adkins with one out in the 10th, took third on Todd Linden's groundout and made it 5-4 on Durham's single.
In the eighth, Alou scored on Durham's groundout to tie it at 4. Alou hit a leadoff single to left and stole second with one out. As catcher Mike Piazza's errant throw sailed into center field, Alou got up and hustled to third. He slid in ahead of the throw from Mike Cameron, who at first seemed surprised Alou was trying to take the base.
Bonds homered to right field on a full-count pitch from Chan Ho Park leading off the second inning, his 16th. Bonds is 31 shy of tying home run king Hank Aaron's record of 755.
Park was making his second start since a stay on the disabled list during which he received three pints of blood to treat intestinal bleeding. The right-hander earned the dubious distinction of tying Greg Maddux, Terry Mulholland, Curt Schilling and John Smoltz as having allowed eight homers each to Bonds, the most by any pitchers.
The 42-year-old Bonds hadn't homered since Aug. 4 against Colorado.
The homer gave Bonds 1,903 RBI, tying him for seventh on the career list with his godfather, Willie Mays.
It was Bonds' 84th homer and 208th RBI against San Diego, his most against any opponent. His 44 homers in San Diego are his most in any road city.
Todd Greene also homered for the Giants, his first this season.
Giants lefty Noah Lowry allowed the first three Padres homers.
Giles connected with two outs in the first, the second time this season he's homered in consecutive games. It was his 10th.
After Bonds tied the game at 1, San Diego's Josh Barfield hit a sacrifice fly in the second. San Francisco's Todd Greene tied it in the third with his leadoff homer into the second deck in left field.
Johnson's first homer was to left with one out in the third. Bellhorn made it 4-2 when he homered into the front row of the home run porch in the right-field corner, where it hit off a fan's glove and fell back onto the field. It was Bellhorn's eighth.
Park allowed Durham's RBI double in the sixth that pulled the Giants to 4-3.
Park allowed three runs and five hits in 5 1/3 innings, struck out three and walked three. Lowry went six, giving up four runs and five hits, with five strikeouts and three walks.
- Bonds was going to get Thursday off anyway, manager Felipe Alou said.
- Piazza was back in the starting lineup two nights after being forced out after getting hit on the forearm by a pitch.
- Padres reliever Scott Linebrink allowed a run for the fourth straight appearance.
- San Diego is 0-for-22 with runners in scoring position in the series.