J.D. Martinez hits an RBI single in the bottom of the eighth inning to give the Red Sox the lead in their 2-1 win over Kansas City on Friday in Boston. Michael Dwyer/Associated Press

BOSTON — J.D. Martinez had an RBI single in the eighth inning and the Boston Red Sox rallied late to beat the Kansas City Royals 2-1 on Friday night.

Martinez’s single to left was just the third hit for Boston, which had just tied it up when reliever Scott Barlow (4-2) walked Alex Verdugo with the bases loaded after Dylan Coleman issued two walks to start the inning.

Garrett Whitlock (4-2) gave up a hit in the eighth and Matt Strahm got the last three outs for his fourth save.

Boston had lost six of eight, including a two-game sweep by the Yankees at home this week and nearly fell to the struggling Royals.

Kansas City, which has lost four straight and eight of 10, led 1-0 after MJ Melendez opened the sixth with a triple and easily scored on a single by Salvador Perez.

The Royals finished with eight hits – all coming from different players. Only Nicky Lopez, who batted eighth, failed to get a hit.

Advertisement

Jonathan Heasley started and pitched 6 2/3 scoreless innings for the Royals, allowing two hits and striking out five.

Michael Wacha went seven innings for Boston, giving up one run and seven hits while striking out four.

Melendez led off the sixth with a drive deep to center, where Kiké Hernández leaped high at the base of the wall but couldn’t quite reach the ball. Melendez was already well around second before Tommy Pham ran over from left and got the ball back to the infield.

Coleman started the eighth for Kansas City and issued back-to-back walks. Barlow loaded the bases by walking Rafael Devers, struck out Xander Bogaerts, but walked Verdugo on four pitches with Hernández trotting home for the tying run.

Martinez was next and lined a single to left that easily scored Abraham Almonte, who pinch-hit for Kevin Plawecki and drew the second walk of the inning.

Boston squandered an opportunity in the fifth after a pair of walks and a single by Christian Arroyo loaded the bases with one out for Hernández, who grounded into a double play.

Advertisement

HOLD UP

Some baserunning mistakes caught both clubs early in the game. Devers singled for Boston with one out in the first, but strayed way too far when Bogaerts hit a soft fly that Bobby Witt Jr. caught and easily made the throw to double-up Devers.

In the third, Dozier led off with a liner off the Green Monster for the Royals’ first hit, but attempted to stretch it into a double and was easily caught by Pham’s throw from left.

TRAINER’S ROOM

Royals: Witt fouled a ball off the top of his left foot in the sixth and needed a few minutes before stepping back into the batter’s box. Manager Mike Matheny and a member of the Royals’ training staff came out of the dugout to make sure the star rookie SS was OK.

Red Sox: 2B Trevor Story was out of the lineup for the third straight game since injuring his left heel on a base Sunday at Baltimore. Manager Alex Cora said Story is improving and could return to the lineup this weekend.