MIAMI -- In a game that featured five lead changes, the Miami Marlins rallied to beat the San Francisco Giants 6-5 on Sunday afternoon at Marlins Park.
The Marlins avoided what would have been a three-game road sweep for the Giants.
Miami's winning eighth-inning rally started with a leadoff single by Ed Lucas. With one out, Jeff Mathis lofted a fly ball to shallow center. Andres Torres, who had been brought in for defense, failed to make the diving catch, and when the ball bounced off his glove toward left field, Lucas raced home.
Steve Cishek pitched a scoreless ninth for his 27th save of the season. He has 22 in a row, the second longest streak in Marlins history behind Todd Jones' 27 in 2005.
The win went to reliever Chad Qualls (4-1) and the loss to reliever Sandy Rosario (3-1).
Neither starting pitcher -- Madison Bumgarner for the Giants and Tom Koehler of the Marlins -- was very effective, and both came away with no-decisions.
The Giants opened the scoring with Hunter Pence's two-out, two-run homer in the first inning. The 420-foot blast, which landed beyond the sculpture in left-center field, was his 15th of the season.
Mathis cut the Giants' lead in half, leading off the third inning with a solo homer to left.
The Marlins scored twice in the fourth to take a 3-2 lead. Giancarlo Stanton led off the inning with a single and advanced a base when Justin Ruggiano reached on catcher's interference ruled against Hector Sanchez.
Lucas and Adeiny Hechavarria then cashed in with run-scoring singles.
The Giants tied the score with two outs in the fifth when Pence slapped a high 0-2 pitch the opposite way to right field. The single scored Gregor Blanco, who started the rally with a one-out single.
Miami surged ahead 4-3 in the fifth when Donovan Solano drew a walk and advanced to second on Logan Morrison's single. With two outs and a 3-2 count, Solano and Morrison were on the move. And when the low fastball darted inside and got away from Sanchez for a wild pitch, Solano scored all the way from second.
The Giants scored twice in the seventh to take a 5-4 lead. Brandon Crawford hit a solo homer to right, pulling a fastball from reliever Mike Dunn. Then, with two outs, Pablo Sandoval singled and scored from first on Sanchez's double to left.
Miami came right back in the bottom of the seventh, tying the score when Solano's double drove in Christian Yelich, who had walked.
NOTES: The Giants rested C Buster Posey for the second time in three games. They also sat 2B Marco Scutaro, who tweaked an ongoing back injury and was lifted halfway through Saturday's game. ... Marlins 3B Placido Polanco, who was hit in the back of his batting helmet by a fastball on Friday night, sat out his second straight game. ... Next up for the Marlins is a much-hyped local event: Miami Rookie of the Year candidate Jose Fernandez pitches against the visiting Los Angeles Dodgers and slugger Yasiel Puig, the ROY front-runner. Fernandez and Puig are both Cuban natives, and Miami has the largest concentration of Cuban exiles in the nation. ... The Giants return home for three games against the Boston Red Sox followed by four against the Pirates. The Giants will start RHPs Tim Lincecum, Ryan Vogelsong and Chad Gautin against Boston.