SAN DIEGO -- When Barry Zito failed to do the job, the San Francisco Giants relied on their bullpen to come through.
Zito was well on his way to a major-league high 17th loss before the bullpen shut down the Padres with 6 1/3 scoreless innings and the Giants came back from a four-run deficit for an 8-6 win in 10 innings on Sunday.
"It's a great win when you are down by four and come back to win," Giants manager Bruce Bochy said. "That game was won for us by the bullpen."
The six San Francisco relievers who followed Zito combined to allow just three hits, although they did walk five batters.
"You never know what's going to happen in a game," said closer Brian Wilson, who got three outs for his 39th save in 43 chances. "All you can do it hold the other team down and hopefully, your guys can come up with enough runs to make a difference."
San Francisco has won nine of 11.
The Padres (57-93) remained one-half game ahead of the Nationals for the worst record in the majors. The clubs play a three-game series next weekend in Washington.
Rookie Pablo Sandoval scored the go-ahead run on a wild pitch in the 10th.
Sandoval led off the 10th with a double against rookie Dirk Hayhurst (0-2), the Padres' eighth pitcher. Sandoval went to third on Travis Ishikawa's single to left, and scored when Hayhurst bounced a curveball in the dirt that got away from catcher Nick Hundley.
Aaron Rowand walked on the wild pitch, and Hayhurst was replaced by Scott Patterson. The right-hander walked another to load the bases and then walked pinch hitter Rich Aurilia to force in another run.
"He's definitely talented," Hayhurst said about Sandoval. "I know he can hit and he's been hot lately. You've to make your pitches and execute well to get a guy like him out."
Zito has struggled for the second straight season after signing a seven-year, free-agent deal with San Francisco before the 2007 season. Zito was well on his way to a major-league high 17th loss, when the bullpen shut down the Padres and the offense came back from a 6-2 deficit for the win.
Rookie Sergio Romo (2-1) pitched the ninth inning for the win.
"It was just one of those days," Zito said. "Fortunately, the guys in the pen picked me up."
Zito was touched for six runs -- five earned -- and seven hits in 4 2/3 innings. He walked five, including three in San Diego's four-run second inning, threw a wild pitch and left trailing 6-2.
"I didn't feel good out there in the second inning," Zito said. "Rhythm wise I was out of whack."
Only one of the Padres' 10 batters who walked ended up scoring.
San Diego missed a chance to go ahead in the eighth when left fielder Randy Winn threw out Luis Rodriguez at home on a one-hop strike after Will Venable's one-out single. Rodriguez was blocked off the plate by Sandoval.
After Alex Hinshaw gave up consecutive walks to Edgar Gonzalez and Brian Giles to load the bases, Adrian Gonzalez struck out for the third time.
"I thought to myself that I have to block the plate so he cannot score," said Sandoval, who played the game with the flu.
San Francisco came back to tie the game at 6 with four runs in the sixth off Cla Meredith on five consecutive singles and a sacrifice fly.
"Cla had a rough outing," Padres manager Bud Black said. "Hayhurst ran into a pretty hot hitter. It looked as though he had (Sandoval) struck out, but he didn't get the call."
Ishikawa had three hits for the Giants.
Padres right-hander Cha Seung Baek left the game with a strained right triceps muscle in the second inning. He allowed one run and two hits with two walks.
Zito, who is tied with Cincinnati's Aaron Harang and Detroit's Justin Verlander for most losses in the majors at 16, also leads the majors in walks (97), and tops the NL in runs allowed (111) and earned runs allowed (100).