Cain provided his own insurance run and limited Lance Berkman to only a base hit.
"[Bonds] told me last year he'd seen my first and last home run," said Cain, who now has the indicted home run king's old corner locker. "You run into them every once in a while. I guess if you get your 245-pound body into it, you can get it to move a little."
It was the fourth career homer and second this season for Cain (2-3), whose drive to left leading off the fifth put the Giants up 4-1. He also connected on April 12 against St. Louis after hitting two for Bonds to see last August in the slugger's final season for San Francisco.
"He did it all," Giants manager Bruce Bochy said of Cain. "He hit a home run and pitched eight innings. Today he looked like he was very determined to get it done."
The Giants started the game with three straight extra-base hits against Brandon Backe (2-5) on the way to a quick 3-0 lead -- a leadoff triple by Fred Lewis, then the doubles by Vizquel and Winn. Winn scored on a passed ball after moving to third on Bengie Molina's fly out.
Carlos Lee hit his eighth homer on an eighth-inning solo shot, but Houston lost for the first time in five games so far during its season-long 10-game road trip.
Berkman singled in the third for a 12-game hitting streak a day after connecting for his 13th home run in Monday's 7-3 win. Cain struck him out swinging to start the eighth, one of Cain's five strikeouts in eight impressive innings. Berkman also drew an intentional walk from Cain in the first.
Cain, who allowed two runs on seven hits and walked four, got better as the game went on. Brian Wilson worked a perfect ninth for his NL-leading 12th save.
"We were just joking in the shower that the way he started wasn't the right way. He wasn't hitting his spots," Molina, the catcher, said of Cain. "Maybe he was a little excited. After that, he got into a nice groove and did the job."
Hunter Pence extended his hitting streak to 11 games with a sixth-inning double, while J.R. Towles snapped an 0-for-20 stretch with his two-out single in the second for the Astros. Lee then got Houston on the board with an RBI single in the third.
The Astros got a scare in the bottom of the eighth. Pence, the right fielder, and second baseman Kaz Matsui collided trying to chase down Molina's bloop single in shallow right. Matsui's left knee banged into Pence's right knee and both were slow getting up as the Astros' trainer ran out to check on them. They stayed in the game.
"We kind of fell all over the place tonight," Houston skipper Cecil Cooper said. "We didn't have an error, but we didn't make the plays we should have."
Backe, who lost consecutive starts for the first time this year and his third in four, was tagged for four runs -- three earned -- on seven hits in six innings. He struck out three and had a season-low one walk.
"When the first batter of the game gets a triple, you want to limit it to just him scoring and leave it at that," Backe said. "The ball dropped and Vizquel made it to second on hustle and scores on the next play. The passed ball was a cutter that cut quite a bit. I didn't throw the ball horribly."
Lewis missed hitting for the cycle for the second time in his career by a home run. He flied out to center in the seventh in his final opportunity.
"I was really thinking about it," he said. "They didn't want to pitch to me. I was like, man, I've got to do this again."
Second baseman Ray Durham returned to San Francisco's lineup after being limited to three pinch-hit appearances in the previous eight games because of tightness in his right hamstring. Durham went 1-for-2 with a walk.
Houston third baseman Ty Wigginton was held out of the lineup after getting hit in the left ribcage area Monday. He had X-rays and could need a couple of days off, Cooper said.
Astros LHP Wandy Rodriguez threw 60 pitches in a simulated game with no problems, a step in his recovery from a strained left groin that put him on the disabled list April 20. He's scheduled to pitch another session Friday. ... Vizquel, who came off the disabled list Saturday following arthroscopic left knee surgery Feb. 27, is scheduled to get the day off for Wednesday night's game. ... Giants LHP Barry Zito celebrated his 30th birthday. ... San Francisco RHP Kevin Correia, sidelined with a strained left side muscle, is slated to throw about 10 pitches off a mound Wednesday.