Brandon Crawford delivered a tiebreaking two-run double in the eighth inning, and San Francisco broke a seven-game losing streak by rallying past Miami 3-1 Thursday.
''You go through these things, and there's no question a win does a lot for a club,'' San Francisco manager Bruce Bochy said.
The Giants averted a series sweep against the team with the National League's worst record, and left town 2 1/2 games ahead of Miami.
''That was the goal coming into today - break the streak,'' Crawford said. ''It will be a happy flight.''
San Francisco's Tyler Beede, recalled before the game from Triple-A Sacramento, allowed one run in six innings to lower his ERA in four appearances to 7.82.
''What a great start,'' Bochy said. ''We needed it in the worst way.''
Beebe earned another start next week at the Mets, Bochy said. Three relievers completed a seven-hitter.
''We won a game we needed to win to get over that hump,'' Beede said.
The Giants, who won with six hits, trailed 1-0 in the seventh when Crawford doubled and scored on a single by Mike Yastrzemski, who earned his first career RBI.
With the score 1-all, Adam Conley (1-5) walked pinch hitter Buster Posey in the eighth. Brandon Belt followed with a broken-bat single, and Evan Longoria walked to load the bases. Crawford greeted Wei-Yin Chen with a ground-rule double for a 3-1 lead.
It was a heady moment for the Giants, who were outscored 62-20 during their losing streak.
''We're sputtering a little bit, and it was good to see Craw deliver,'' Bochy said. ''That's what we're used to.''
Crawford hiked his average to .215.
Reyes Moronta (2-4) worked a scoreless seventh, and Will Smith pitched a perfect ninth for his 13th save.
Sandy Alcantara pitched six innings, singled home the Marlins' lone run and departed with a 1-0 lead. He worked around two hits, five walks and a hit batsman.
''I feel good, but also feel bad,'' he said. ''The bases on balls were a problem.''
Marlins manager Don Mattingly said the weekday game after a night game was part of a trend, where quick turnarounds lead to flat performances.
''You're seeing nowadays just not a lot of juice either side,'' Mattingly said.
Marlins 1B Neil Walker (strained right quad) pulled up running out a groundout in the sixth inning, left the game and is day to day.
''We don't know how severe it is,'' Mattingly said. ''The way he kind of pulls up tells you it's going to be a little bit.''
Before the game the Marlins recalled RHP Jeff Brigham from Triple-A New Orleans and optioned RHP Elieser Hernandez to New Orleans. OF Isaac Galloway cleared waivers and accepted outright assignment to New Orleans.
Giants: LHP Drew Pomeranz (1-5, 6.45) is scheduled to start Friday when the Giants begin a three-game series in Baltimore. Pomeranz lasted just 2 2/3 innings in his most recent outing, when San Francisco lost to Arizona 18-2.
Marlins: LHP Caleb Smith (3-2, 3.05) is scheduled to take the mound Friday at San Diego to start a six-game trip. Smith has allowed one run in 12 1/3 innings in two starts against the Padres.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Follow Steven Wine on Twitter: http://twitter.com/Steve-Wine.
Copyright 2019 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.