Yandy Diaz went 3-for-4 with two doubles and Kevin Kiermaier had four RBIs to lead visiting Tampa Bay over Boston.
Kiermaier's bases-clearing double off Boston starter Nick Pivetta started the scoring in the first inning. The Rays later broke a 3-3 tie with a four-run sixth and added one in the seventh to win for the third time in five games.
Isaac Paredes and Rene Pinto both had two hits, while Wander Franco scored three runs and stole a base.
Jeffrey Springs struck out five with five hits and three runs over four innings while winning pitcher Ryan Thompson (2-2) worked around two hits for a scoreless fifth.
Boston brought the tying run to the plate by loading the bases in the ninth, but a pop-out to Wander Franco ended the game.
After missing Monday's game with a thigh laceration, Xander Bogaerts homered and drove in three for the Red Sox, who had won back-to-back games. Trevor Story also left the yard, J.D. Martinez went 3-for-5 and scored a run, and Jarren Duran added two hits.
In the loss, Pivetta (8-6) allowed a season-high seven earned runs on eight hits and two walks while striking out four in 5 2/3 innings.
Tampa Bay loaded the bases on two hits -- including a Diaz leadoff double -- and a walk before Pivetta recorded an out. Kiermaier made it 3-0 on one swing of the bat, clubbing a one-out double off the Green Monster.
A line-drive double play helped the Boston righty escape the inning without further damage, but the Rays logged three hits in the first inning after being shut out with two hits on Monday.
In the bottom of the first, Bogaerts cut into Boston's deficit with his first homer since June 3, a two-out, two-run shot to center.
Boston evened the score on Story's second-inning solo homer over the Monster in left-center. It was his second in as many games.
The visitors moved back ahead in the sixth, initially taking the lead on a fielder's choice by Kiermaier, who later scored on Taylor Walls' sacrifice fly. Pinto's check-swing infield single and Diaz's line base hit to left with two outs also plated runs.
In the seventh, Tampa Bay added to its lead with Paredes' single. The home team got a run back as Duran doubled and scored on Bogaerts' sac fly.
--Field Level Media