Gregor Blanco went 2-for-2 with three RBI and two runs scored for the Giants, who scored eight times in the sixth inning to rally from a 7-1 deficit.
Angel Pagan added a pair of hits, including a two-run single, while Hector Sanchez knocked in two with a base hit.
San Francisco's offense overcame a rough start from Tim Lincecum, who was tagged for seven runs and 11 hits -- including three homers -- in just 4 2/3 innings. The right-hander did record seven strikeouts, however.
Lincecum surrendered a three-run homer to Jason Donald in the fifth inning and solo blasts to Salvador Perez and Carlos Peguero.
Royals starter Yordano Ventura yielded just one run over five innings of work, but Louis Coleman was rocked for six while managing only one out in relief.
Notable deaths of 2014 [PHOTOS]