Tanaka and Sandoval, who homered and scored twice, complemented Madison Bumgarner's seven-inning effort. The left-hander overcame a shaky first inning and improved to 6-1 in his last seven starts. The only Giants starter to win a decision since June 14, Bumgarner (10-5) retired 20 of the final 21 Padres he faced.
Entering the game with a Major League-low 21 runs scored in July, the Giants broke a 2-2 tie in the eighth inning with a pair of runs. Tanaka, whose sixth-inning single accounted for his first big league RBI and forged the deadlock, singled again to open the eighth. He then stole second base, went to third on an infield out and came home on Gregor Blanco's ground-rule double. Buster Posey added an RBI single to help the Giants secure their second victory in their last 10 games.
Hours earlier, Giants right fielder Hunter Pence dipped into his well of philosophy by quoting Babe Ruth. "It's hard to beat someone who never gives up," Pence said, repeating the baseball demigod.
Tanaka fit that description as the Giants (41-50) leapfrogged the Padres (41-52) to escape last place in the National League West. A veteran of 13 professional seasons in Japan who yearned to succeed in American organized baseball, Tanaka started his third game in left field and enjoyed his most productive effort since San Francisco purchased his contract from Triple-A Fresno on Tuesday.
"I wanted to show my strengths in baseball," Tanaka said through an interpreter, Giants bullpen catcher Taira Uematsu. "This is what I'm good at."
This was not the erratic, tentative Tanaka who hit .229 in 19 Cactus League games before the Giants sent him to Minor League camp.
"He looks very comfortable up here," Giants manager Bruce Bochy said. "That's what's impressive about him. He worked hard. He earned his position and he has taken advantage of it."
Another resurgent Giant was Sandoval, who opened San Francisco's scoring against Padres starter Jason Marquis with a fourth-inning leadoff homer. It was Sandoval's first long ball since May 21, ending a homerless streak of 101 at-bats. Sandoval, who also walked and scored in the sixth inning, recorded his first two-run game since May 11 against Atlanta and notched his first run of any kind since June 7 at Arizona after not crossing home plate for 16 games.
Sandoval's sudden outburst didn't surprise Padres manager Bud Black.
"With Sandoval, it can come anywhere," Black said. "He's one of the true bad-ball hitters. He's always a threat."
Lately, Sandoval had looked anything but threatening, batting .140 (8-for-57) since returning from the disabled list on June 24. He agreed with Bochy's observation that he has begun to see pitches better in the last couple of days, but concluded, "Winning is more important than my stats."
One Giant who has accumulated success and the numbers to back it up is Bumgarner, who has allowed three runs or fewer in each of his last seven starts. The first-time All-Star is 6-1 with a 2.30 ERA and a .162 opponents' batting average in that stretch.
Bochy said that Bumgarner repeated a mechanical flaw in the first inning, which caused his pitches to flatten out and enabled the Padres to amass three hits and two runs. But Bumgarner said that he didn't have to adjust too much afterward.
"I felt like I made some pretty good pitches in the first inning and they happened to hit them," he said.
Sergio Romo pitched a perfect ninth for his 21st save, sealing San Diego's 12th loss in 13 games.
"We needed a win," Romo said. "We hadn't been able to play victory music after too many games lately."