The Giants took three of four at Citi Field. The Mets lost a home series for the first time since June 10-12 against Milwaukee.
Sandoval hit a two-run double in the third, then delivered again in the ninth.
Gregor Blanco singled with two outs off Jenrry Mejia (5-4) and stole second, and Buster Posey drew his fourth walk of the game. Sandoval followed by slicing a ground-rule double into the seats down the left-field line.
Mejia, the Mets' sixth pitcher of the afternoon, had allowed just one earned run since June 18.
Sergio Romo (5-3) got the win with one scoreless inning and Santiago Casilla pitched a perfect ninth for his ninth save.
The Giants scored the tying run in the seventh off Jeurys Familia, who had gone 13 straight relief appearances since June 30 without permitting an earned run.
Hunter Pence led off with a long drive that glanced off the glove of leaping left fielder Chris Young as center fielder Juan Lagares also jumped for the ball at the wall.
After Blanco walked, Familia threw a wild pitch that made it 3-all. Sandoval singled, and Lagares threw out Blanco at the plate.
Mets manager Terry Collins was ejected at the end of the seventh by plate umpire Ben May for arguing balls and strikes.
Daniel Murphy hit a two-run homer in the first. He singled in the fifth off Tim Hudson, stole second and later scored on David Wright's infield single.
Giants: Catcher Hector Sanchez (concussion) traveled from New York to begin a rehab assignment with Triple-A Fresno. ... Outfielder Angel Pagan (back inflammation) is 3 for 5 with two doubles and a walk in two games in an Arizona League rehab assignment. ... Manager Bruce Bochy intended to give Posey the day off, then changed his mind. "The games have been somewhat short and crisp, which has helped matters. The weather's been unbelievable, which has helped matters," Bochy said. "So he is going to go today and be off tomorrow."
Mets: Matt Harvey, who threw off a mound Friday at Citi Field for the first time since undergoing Tommy John surgery last October, is scheduled to do the same Tuesday at the team's spring training complex in Port St. Lucie, Florida.
Giants: San Francisco plays the fifth of a 10-game road trip with a three-game set starting Tuesday night in Milwaukee. Giants righty Tim Lincecum (9-7, 4.21 ERA) faces Jimmy Nelson (1-2, 4.30). It will be the first meeting of the teams this season.
Mets: New York begins a three-game series Tuesday night in Washington. Mets righty Zack Wheeler (6-8, 3.60) faces Gio Gonzalez (6-7, 3.88). The Nats have won five of six meetings against the Mets this season. They meet 13 times in the final eight weeks.