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 RBIs. "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."
This one helped the Red Sox hold steady atop the AL East with a 6 1/2 game lead over the Yankees, who got a walkoff homer from Neil Walker to beat the Chicago White Sox 5-4.
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.
Eduardo Nunez followed with a grounder to Riddle, who stepped on second but sailed his throw well past first baseman J.T. Realmuto, and Martinez came around with the winning run.
"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.
Bradley hit a two-run single with two outs in the eighth off Marlins reliever Tayron Guerrero, and Ian Kinsler then scored on Guerrero's wild pitch to take a 7-6 lead.
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.
RHP Trevor Richards (3-7, 4.23 ERA) starts for Miami against Boston LHP David Price (14-6, 3.50), who has won his last three starts.
More AP MLB: https://apnews.com/tag/MLB and https://twitter.com/AP_Sports