Bumgarner (2-3) earned his second win this season despite an erratic outing. Making his seventh start after missing the first two months with a broken left pinkie, Bumgarner allowed four runs and seven hits in 5 1/3 innings. He walked two and hit a batter with a pitch.
The Giants bailed out their ace with a pair of three-run innings and a five-run sixth while setting a season high for scoring.
After Jose Martinez's RBI single off Bumgarner in the fifth put St. Louis ahead 4-3, San Francisco rallied against reliever John Brebbia.
Belt doubled and went to third on All-Star Brandon Crawford's single. Sandoval followed with his eighth home run, a three-run drive that bounced into the waters of McCovey Cove.
Sandoval added a two-run single in the sixth. The five RBIs were one shy of his career high.
Brebbia (1-3) also took the loss against the Giants on Friday.
Cardinals starter Jack Flaherty gave up three runs, two earned, in 2 1/3 innings.
Cardinals: CF Tommy Pham left in the seventh after fouling a ball off his left foot. ... C Yadier Molina sat out for the second consecutive day because of soreness in his right shoulder. ... OF Dexter Fowler was back on the bench, one day after making his first start since June 27.
Giants: Hernandez exited for unknown reasons after hitting a two-run single in the sixth. Derek Holland, who has been pitching out of the bullpen lately, was brought in as a pinch-runner.
Cardinals: All-Star RHP Miles Mikolas (9-3, 2.63 ERA) starts Tuesday in Chicago against the White Sox. Mikolas matched his career high for walks in his last outing but is second in the NL in fewest free passes per nine innings (1.4) among qualifying pitchers.
Giants: LHP Andrew Suarez (3-5, 3.92) faces the Cubs on Monday night at home. Suarez took the loss in his last start despite allowing only one run over seven innings.