Updated

Giancarlo Stanton hit a home run that he hoped ended both a personal slump and the Miami Marlins' skid as well.

Not quite.

The Boston Red Sox rallied for three runs in the eighth inning for a 6-5 victory Thursday night, completing a three-game sweep of the slumping Marlins.

"Especially here, it's never going to be over until the last out is made," said Stanton, whose solo shot off Daisuke Matsuzaka was the first of two runs the Marlins scored in the sixth inning while taking a 5-3 lead. "It was a good jump start to get us back on top and the game back in our hands. But unfortunately it didn't work out that way."

Not much has for the Marlins lately.

The Marlins took a lead in all three games of the series but lost them all as they dropped their fourth straight overall and 13th in their last 15.

"Finally we got the lead late in the game. Our bullpen has been great all year long. We feel good about ourselves. We get the matchup we want, don't work," Marlins manager Ozzie Guillen said. "You've got to fight the fight. They want to quit, I'd like to know. I'm a fighter. I'm going to fight through it."

Boston tied the score on a two-run homer by Will Middlebrooks, who drove in four runs. Ryan Kalish then singled, raced to third on a groundout to first and scored on Daniel Nava's single up the middle.

Alfredo Aceves pitched a perfect ninth for his 18th save in 21 opportunities. Scott Atchison (2-0) allowed one hit over the seventh and eighth.

The Red Sox won their fifth straight game and the seventh in their last eight as they matched their season-best mark of three games over .500.

Stanton, in a 2-for-31 slump, hit his first homer in 12 games and 15th of the season to make it 4-3. That ended Matsuzaka's streak of 14 consecutive outs and brought in lefty Andrew Miller.

He retired the next batter before giving up a single to Greg Dobbs and a run-scoring double to Omar Infante.

Jarrod Saltalmacchia started the winning rally in the eighth with a double off Randy Choate. Edward Mujica (0-3) came in and served up Middlebrooks' long, tying shot.

Then Nava, who had six singles in the last two games, lined a clean single to center.

"I believe in my bullpen. We had the matchup we wanted," Guillen said. "They beat our matchups."

In just his third start of the season since having Tommy John elbow surgery on June 10, 2011, Matsuzaka gave up a leadoff single in the first to Jose Reyes, who went to third on a slow grounder to shortstop Mike Aviles, who got the out at first. Stanton walked and stole second and both runners scored on a single by Dobbs. After Dobbs stole second, he came in on a single by Infante.

Matsuzaka ended the inning by retiring Scott Cousins on a fly ball to center and didn't allow another runner until Stanton homered.

In his previous start, a 3-0 loss to the Chicago Cubs, he set down 13 of his last 14 batters after allowing three runs.

Carlos Zambrano gave up one hit through three innings before Boston tied the game with two runs in the fourth and one in the fifth.

He hit the first two batters, Cody Ross and Saltalamacchia, in the fourth. Ross scored on a single by Middlebrooks and Saltalamacchia came in on a sacrifice fly by Aviles.

The Red Sox evened the score at 3 on another RBI single by Middlebrooks, driving in Adrian Gonzalez, who led off the fifth with a walk.

NOTES: Boston 2B Dustin Pedroia returned to the lineup after missing one game as a precaution when he felt discomfort in his right hand on his last at-bat in Tuesday night's 7-5 win. ... Marlins owner Jeffrey Loria spoke to his struggling team before the game. ... Miami optioned RHP Chris Hatcher to New Orleans and recalled LHP Mike Dunn from the Triple-A team. ... The Red Sox begin a three-game series at home against the Atlanta Braves on Friday night, sending Jon Lester (4-4) to the mound against Jair Jurrjens (0-2). ... Anibal Sanchez (3-5) is scheduled to pitch Friday night for Miami in the opener of a three-game home series against Toronto, which plans to start Ricky Romero (7-1).