BOSTON -- The Boston Red Sox avoided their first four-game losing streak of the season -- barely.
J.D. Martinez scored when Marlins shortstop JT Riddle threw away a potential double-play ball in the ninth inning, lifting Boston over Miami 8-7 on Tuesday night following a wild, back-and-forth final two innings.
"It was pretty amazing that we were able to pull off a win tonight," said Jackie Bradley Jr., who had two hits and two RBI. "I don't believe in ugly wins. I believe in wins. As long as we continue to win, I don't care how ugly it is."
Miami scored five runs in the eighth inning to lead 6-4, allowed three runs to Boston in the bottom of the inning, then tied the game at 7 in the top of the ninth against closer Craig Kimbrel (4-1).
"We didn't pitch well of the last third of the game, but we swung the bats well and we ended up winning," manager Alex Cora said. "We took advantage of their mistakes."
Martinez started the final rally on a one-out single and went to second on Xander Bogaerts' hit.
"It's a two hopper -- step on the bag and throw the ball to first. As simple as that," Riddle said. "I throw the ball 80 feet and lose the game."
Drew Steckenrider (4-3) was stuck with the loss.
Nunez homered in the sixth to put Boston ahead 4-1, a lead that held until Matt Barnes' melted down in the eighth. Realmuto and Starlin Castro hit back-to-back home runs during the five-run inning, which also included a two-run single by Rafael Ortega.
"Obviously the ending was not very good, but it was kind of the way we played all night," Marlins manager Don Mattingly said.
Before batting around in the eighth, Miami's only score came on Isaac Galloway's solo homer in the third.
With two starters out of the rotation because of injuries, Boston's bullpen has been pushed lately and the wear has shown during the recent slide. After Barnes' implosion in the eighth, Kimbrel struggled in the ninth with two walks before allowing Magneuris Sierra's tying single.
"If we're going to be a successful team we're going to have to turn it around and we know that," Kimbrel said. "This is the team that we have and this is the team that we're going to make a run with, so we've got to figure it out or we're not going to win. I've got a pretty good feeling we're going to figure it out."
WELCOME BACK JOSE
Jose Urena returned to Miami after a six-game suspension and allowed four runs and six hits and struck out two in six innings. Urena, suspended for hitting Atlanta's Ronald Acuna Jr. with a pitch on Aug. 15, didn't figure in the decision.
Marlins: OF Garrett Cooper will have surgery Friday in Miami to repair a tendon sheath in his right wrist, Mattingly said.
Red Sox: LHP Eduardo Rodriguez (right ankle sprain) will return from the DL and start Saturday when the Red Sox visit the Chicago White Sox. Cora said Rodriguez's return will take some pressure off the starting rotation as well as the bullpen. ... LHP Chris Sale (left shoulder inflammation) played catch Monday, which Cora described as a "good start" but didn't offer a timetable for his return.
More AP MLB: https://apnews.com/tag/MLB and https://twitter.com/AP-Sports
Law: Michael Brantley, Wilson Ramos fill needs for Astros, Mets
Michael Brantley can fill the DH role for the Astros, while the Mets didn't have to gut their farm system in landing catcher Wilson Ramos.
Yankees officially ink J.A. Happ; is Manny Machado next?
Bringing back a 36-year-old pitcher wasn't everything Bombers fans were wishing for. Machado -- and maybe another arm -- joining Happ would make the season bright.
With demand down, Boston might be Craig Kimbrel's best bet
In the same way the Red Sox held out for J.D. Martinez in a crowded market, they could do the same for their free-agent closer.
The state of the starting pitching market
A look at who is still available in free agency, who could be involved in a trade, and the teams that could use a rotation upgrade.
Houston Astros reach two-year deal with Michael Brantley
Michael Brantley adds a needed left-handed presence to the middle of the Astros' lineup, which is heavily right-handed with key cogs Jose Altuve, Alex Bregman, Carlos Correa and George Springer.
CC Sabathia gets $500,000 bonus despite falling short of mark
The New York Yankees gave pitcher CC Sabathia a $500,000 performance bonus, even though the 38-year-old left-hander was ejected from his final regular-season start six outs shy of the 155 innings specified in his contract for the payment.