Sanchez (2-0) struck out five and walked one. Edward Mujica picked up his first save of the season with a scoreless ninth for Miami, which won for the fourth time in six games after having lost six straight.
Hanley Ramirez was hitless in five at-bats but still licked up a pair of RBI, and Brett Hayes had three hits and two runs scored for the Marlins.
Ryan Vogelsong (0-2) went seven innings, giving up two runs -- one earned -- on eight hits, with five strikeouts and four walks for San Francisco.
Gregor Blanco had three hits and two runs scored, and Angel Pagan ran his hitting streak to an NL-best 17 games streak to 17 games for the Giants, who have lost seven straight at home to Miami.
Ramirez drove in Jose Reyes with a groundout in the first inning, and then drove in Hayes with a groundout in the second.