Aaron Rowand went 3-for-5 and scored twice for the Giants, who snapped a two- game losing streak.
Starter Madison Bumgarner tossed 7 1/3 solid innings, allowing just one run on five hits, but did not factor into the decision.
It wasn't a good night for either team's closers. Brian Wilson (6-1) blew his fourth save in the eighth, but still picked up the win after San Francisco batted around to score three runs in the ninth.
Detroit closer Jose Valverde (2-3) suffered the loss after giving up three runs on three hits and two walks in less than an inning. The loss wasted a solid start by Brad Penny, who went seven innings of one-run ball. He allowed just seven hits and struck out two for Detroit, who have dropped three of their last four games.