Early in the 2017 season, Barnes was ejected for the first time in his MLB career, on April 23 by umpire Andy Fletcher, for apparently trying to hit Baltimore's Manny Machado with a pitch in response to a hard slide by Machado on Dustin Pedroia in a game two days prior. The next day, Barnes received a four-game suspension for "intentionally throwing a pitch in the area of the head of Manny Machado." For the 2017 season, Barnes made 70 relief appearances with Boston, compiling a 7–3 record, plus one save, with a 3.88 ERA and 83 strikeouts in innings pitched. Barnes started the 2018 season in his usual role as a member of Boston's bullpen. During the regular season, he appeared in 62 games, compiling a 6–4 record with a 3.65 ERA and 96 strikeouts in innings. In the postseason, he made 10 appearances while allowing one earned run in innings as the Red Sox went on to win the World Series over the Los Angeles Dodgers.