The Boston Red Sox traded Rafael Devers to the San Francisco Giants on Sunday in a deal that could shake up pennant races on both coasts.

The Giants sent right-hander Jordan Hicks, lefty Kyle Harrison, outfield prospect James Tibbs III and minor league righty Jose Bello to the Red Sox for the 28-year-old designated hitter, who had bristled at his demotion from third base this year.

A three-time All-Star who signed a 10-year, $313.5 million contract with the Red Sox in 2023, Devers is batting .272 with 15 homers and 58 RBIs in 73 games this season.

But his relationship with the team began to deteriorate when the team signed Gold Glove third baseman Alex Bregman during spring training and asked Devers to move to DH; he balked before agreeing to the switch. When first baseman Triston Casas sustained a season-ending knee injury, the Red Sox approached Devers about playing the field and he declined, saying the front office “should do their jobs” and look for another player.

Harrison, 23, is 9-9 with a 4.48 ERA and 178 strikeouts in 39 games for the Giants over three seasons. Hicks, 28, was 5-12 with a 4.83 ERA and 139 strikeouts in 42 games over two seasons. Tibbs, 22, was the 13th overall pick in last year’s draft; he is hitting .246 with 12 homers and 32 RBIs in 57 games for Single-A Eugene of the Northwest League this season. Bello, 20, is 1-0 with a 2.00 ERA in eight games for the Giants’ rookie league team in Scottsdale, Arizona.

Red Sox 2, Yankees 0: Brayan Bello struck out eight over seven innings, Rafael Devers homered in his Boston swan song and the Red Sox beat New York for a three-game home sweep that extended their winning streak to five.

Trevor Story added an RBI single for the Red Sox, who have won five straight over the Yankees since losing their first meeting this year. Boston’s winning streak matched its season high.

AL East-leading New York went 0 for 5 with runners in scoring position and was swept in a series for the first time this year, getting shut out for the third time.

Yankees slugger Aaron Judge went 1 for 12 in the series with a solo homer and nine strikeouts, dropping his major league-leading average to .378. He has struck out three or more times in three straight games for the third time in his big league career.

Bello (3-1) gave up three hits, walked three and tossed a career-high 114 pitches.

Devers homered just over the top edge of the Green Monster, making it 2-0 in the fifth against Max Fried (9-2).

Fried, who entered 7-0 with an 0.83 ERA in eight starts after a Yankees’ loss, struck out nine over seven innings, allowing two runs and six hits.

Padres 8, Diamondbacks 2: Nick Pivetta held Arizona to two hits over seven innings and Jake Cronenworth homered as visiting San Diego snapped a three-game losing streak.

Fernando Tatis Jr. had four hits, scored three runs and stole a base for the Padres.

Pivetta (7-2) retired the first 12 Arizona batters before walking Josh Naylor to open the fifth. Eugenio Suárez followed with his 21st home run for the Diamondbacks’ first hit. Pivetta struck out nine.

Phillies 11, Blue Jays 4: Nick Castellanos hit a grand slam, Zack Wheeler pitched six strong innings and Philadelphia completed a three-game home sweep of Toronto.

Alec Bohm also went deep and rookie Otto Kemp, out of Troy High, had four hits, three runs, two RBIs and a stolen base for the Phillies, who have won five of six.

Wheeler (7-2) allowed one earned run on four hits while striking out nine and walking none.

Reds 8, Tigers 4: Elly De La Cruz homered, scored three times and drove in three runs as visiting Cincinnati rallied to defeat Detroit.

De La Cruz singled and scored in the fourth, had an RBI single before scoring in a four-run eighth and hit a two-run homer in the ninth.

Detroit took a 4-2 lead in the seventh when Gleyber Torres hit an RBI single and scored on Riley Greene’s double, but Cincinnati came back in the eighth.

Rays 9, Mets 0: Shane Baz combined with three relievers on a five-hitter, and Tampa Bay won at New York to complete the first three-game series sweep of the Mets this season.

Baz (6-3) allowed three hits and four walks in 6 2/3 innings with six strikeouts.

Jonathan Aranda’s two-run double in the fifth off Max Kranick blew open the game for the Rays.

Cubs 2, Pirates 1 (10): Ian Happ hit a game-ending single in the 10th inning, and Chicago edged Pittsburgh.

The Cubs used a double steal to put runners on second and third in the 10th against David Bednar (1-5). Jon Berti struck out swinging for the first out, but Happ followed with a liner to right.

Astros 2, Twins 1 (10): Victor Caratini tied it with a sacrifice fly in the ninth and Mauricio Dubón hit a walk-off single in the 10th as Houston defeated Minnesota to sweep the three-game series.

Astros starter Brandon Walter gave up a run on six hits with nine strikeouts across 6 2/3 innings.

Brewers 3, Cardinals 2: Christian Yelich homered and Trevor Megill escaped a jam in the ninth inning, sending Milwaukee to a victory over visiting St. Louis.

Drew Avans and Sal Frelick each drove in a run for Milwaukee, which won for the fourth time in six games.

The Cardinals wasted a prime scoring opportunity against Megill in the ninth. Nolan Arenado hit a leadoff single and Nolan Gorman followed with a bunt single.

The runners advanced on a one-out wild pitch, but Megill fanned Victor Scott II and Masyn Winn for his 15th save in 17 opportunities.

Rockies 10, Braves 1: Ryan McMahon hit a go-ahead home run in the seventh and visiting Colorado overcame Grant Holmes’ 15-strikeout performance to beat Atlanta.

Rockies right-hander Austin Gomber allowed two hits and no runs in five innings in his season debut.

Holmes (3-6) allowed three runs — two earned — in 6 1/3 innings.