San Francisco fell behind 5-0 after three innings, but came back to win its fourth straight game.
The Giants batted around in both the fourth and fifth innings while scoring all of their runs, the first four of which were unearned.
That miscue allowed one run to score, another run came in on an infield single by Angel Pagan and Sandoval later contributed his two-run double that brought the Giants within 5-4.
The Giants then loaded the bases with one away in the fifth and Vogelsong drew a walk to force in the first run of the frame. Pagan delivered a sacrifice fly to put San Francisco in front and Crawford singled in another run.
All of that gave San Francisco a 7-5 lead and the Giants held on to make Vogelsong (1-1) the winning pitcher. He allowed four runs on eight hits in six innings. Sergio Romo came on in the ninth to collect his sixth save, tops in the majors.
Scott Feldman (0-2) suffered the loss with only two of the six runs he allowed being earned.
Chicago lost for the fifth time in six games. Anthony Rizzo hit a two-run homer for the Cubs.