Stanton added a run-scoring double in the eighth to back the strong pitching of Ricky Nolasco (11-7), who shut the Giants down on one run and four hits in a 6 1/3-inning start.
Leo Nunez struggled to protect the Marlins' two-run lead in the ninth, allowing a run to score on an Andres Torres groundout. But the Marlins closer fanned Edgar Renteria to end the game with Freddy Sanchez stranded on third, collecting his 24th save.
San Francisco starter Barry Zito (8-6) yielded three runs on eight hits in 6 1/3 innings.
The Giants lost for only the third time in 14 games.
Wisconsin business offering 'therapeutic cuddling' forced to close
Sign language interpreter at Mandela service called out as fake on Twitter