BOSTON — René Pinto hit a two-run home run, Manuel Margot added a pair of RBI singles as part of a four-hit night, and the Tampa Bay Rays held on to beat the Boston Red Sox 9-7 on Tuesday night.

Rays starter Zach Eflin (16-8) yielded three runs off five hits over five innings to earn his third victory in four starts. Pete Fairbanks struck out three in a scoreless ninth to pick up his 25th save.

With the win Tampa Bay (96-62) kept Baltimore’s magic number at two to clinch the AL East following the Orioles’ win over the Nationals.

Boston (76-81) has lost five of its last six games. Emmanuel Valdez had three hits and a career-high four RBIs and Wilyer Abreu added a two-run double for the Red Sox.

Tampa Bay jumped out to a 7-0 lead before Valdez got Boston on the board with a three-run home run in the fifth.

The Red Sox trimmed it to 7-5 in the sixth via Abreu’s two-run double off reliever Kevin Kelly. Justin Turner then dropped in a bloop single off Colin Poche that scored Adam Duvall to get it down to 7-6 in the seventh.

Tampa Bay stretched the lead back to three runs in the eighth off Harold Ramirez’s RBI groundout and Jonathan Aranda’s RBI single.

With Shawn Armstrong on in relief, Boston had a runner on first with one out in the ninth, when Bobby Dalbec hit a grounder to Aranda at first. He tried to throw to second for a potential double play, but it clipped Trevor Story in the back leaving both runners safe.

Valdez doubled, scoring Story and leaving runners at second and third. But Armstrong struck out Connor Wong and Duvall to end the inning.

The Rays entered the day having already secured a wild-card berth and with only slim hopes of overtaking Baltimore.

It led manager Kevin Cash to give starts to some of his younger players to allow some veterans to heal up from some recent injuries.

They responded by tagging Boston starter Tanner Houck (5-10) for seven runs off 10 hits, ending his night after just three innings. It included Pinto’s 424-foot homer to center field, his sixth of the season.

TRAINER’S ROOM

Rays: All-Star first baseman Yandy Diaz (right hamstring) and outfielder Randy Arozarena (right quad tightness), both sat out Tuesday. Cash said both are expected to return to the lineup sometime this week.

Red Sox: Catcher Reese McGuire left the game prior to the start of the third inning after suffering a left thumb contusion while taking warmup throws from Houck. He was replaced by Wong.

UP NEXT

Rays: RHP Tyler Glasnow (9-7, 3.68 ERA) has an 8.22 ERA in his last three starts.

Red Sox: RHP Brayan Bello (12-10, 4.11) will make his 28th start. He is coming off allowing a career-high eight earned runs over three innings last week at Texas.