Kyle Higashioka had three hits and Gleyber Torres hit a two-run double to lead the Yankees (72-72), who won their second straight following a three-game skid. DJ LeMahieu doubled and scored a run for New York.
Rafael Devers hit his 30th home run of the season for the Red Sox (73-71), while Triston Casas had three hits with a double and a run scored.
New York closer Clay Holmes walked three straight Boston batters with one out in the bottom of the ninth, but Alex Verdugo grounded into a game-ending double play for his 19th save.
Right-hander Nick Pivetta (9-9) took the loss despite striking out seven of the first 10 batters he faced and finishing with 10 strikeouts across 5 1/3 innings. Higashioka's two-out single in the third was the first Yankees hit.
New York starter Randy Vasquez allowed only one hit — a Casas leadoff single in the second — before Devers began the fourth with a first-pitch solo homer to right-center.
Casas wound up scoring the second Boston run after his one-out double in the fourth, moving to third on a ground ball and crossing the plate after a wild pitch.
The Yankees batted around and forced Pivetta out of the game in the midst of a three-run sixth that began when Everson Pereira was hit by pitch.
Higashioka followed with his second hit before LeMahieu lined an RBI double to left, making it a 2-1 game. Two batters later, New York took a 3-2 lead as Torres shot a two-run single inside the first base bag.
A walk ended Pivetta's day and reliever Mauricio Llovera stranded the bases loaded to keep the hosts within a run.
The Boston bullpen held the game there, including John Schreiber striking out the side in the ninth to cap two scoreless innings.
Three New York relievers allowed just one combined hit after Vasquez and Brito worked the first six frames.
Vasquez allowed two runs on three hits and struck out three over 3 2/3 innings.
—Field Level Media