Joe Borchard added a two-run homer and Hanley Ramirez had two runs, one hit and one RBI for the Marlins (21-36), who averted a three-game sweep.
Winning pitcher Dontrelle Willis (3-6) went the distance on a six-hitter in his best outing of the season.
He walked three and struck out three and has won two straight decisions since losing six in a row.
Both Randy Winn and Todd Greene had two hits; while two days off the 15-day disabled list with a sprained right ankle, Moises Alou had one hit and knocked in the lone run for the Giants (31-28), who had a three-game winning streak broken.
Loser Jamey Wright (5-5) gave up six runs and five hits in 4 1/3 innings.
Notable deaths of 2014 [PHOTOS]
Julius Randle breaks leg during NBA debut