ST. PETERSBURG — Nelson Cortes took a three-hit shutout into the ninth inning, Matt Carpenter sparked a go-ahead, three-run rally in his Yankees debut and New York beat the Tampa Bay Rays 7-2 Thursday night in the first meeting of the AL East rivals this season.

Cortes (4-1) won his third straight start, striking out five and walking one in eight-plus innings. The 27-year-old left-hander lowered his ERA to 1.70, retiring 14 in a row during one stretch. He threw 77 strikes among a career-high 109 pitches.

Cortes has allowed three earned runs or fewer in 18 consecutive starts, two shy of the team record set by Russ Ford in 1910.

Wandy Peralta relieved after Wander Franco’s leadoff single in the ninth and allowed Manuel Margot’s run-scoring infield hit and Isaac Paredes RBI grounder before finishing a six-hitter.

New York, dealing with a string of injuries, signed Carpenter to a $1 million, one-year deal before the game and inserted him into the starting lineup when Aaron Hicks was scratched because of right hamstring tightness. The 36-year-old Carpenter, released last week from Texas’ minor league system, went 0 for 2 with a pair of groundouts and also walked.

Aaron Judge had pair of RBI to raise his total to 36.

The Yankees opened a 5 1/2-game lead over the Rays by winning the opener of a four-game series, the first of 10 games between the teams in a 28-day span. New York won its third straight following a season-worst three-game losing streak and improved the major leagues’ best record to 32-13, matching 1994 for the Yankees’ second-best 45-game start behind 35-10 in 1998.

Ryan Yarbrough (0-1) held the Yankees hitless through five innings before hitting Carpenter leading off the sixth.

Marwin Gonzalez singled, and Carpenter scored the go-ahead run on Judge’s single. After Anthony Rizzo flied out, Ryan Thompson relieved, Judge stole second and Gleyber Torres flied out.

Miguel Andújar hit a hard grounder off the glove of shortstop Tyler Walls, who recovered and made a one-hop throw to that bounced off the glove of first baseman Harold Ramírez. Andújar was credited with an RBI and another run scored on the error.

Ralph Garza added a run-scoring wild pitch in the seventh. Judge hit a sacrifice fly in the eighth and Anthony Rizzo followed with an RBI double off Brooks Raley, with a second run scoring on an error by right fielder Vidal Bruján,

Yarbrough gave up three runs — two earned — and two hits in 5 2/3 innings

SLOPPY

Tampa Bay allowed two unearned runs; The Rays had 30 coming in, the second-highest total behind Pittsburgh. Tampa Bay also threw a pair of wild pitches, raising its total to 20.

HIGHS AND LOWS

Tampa Bay is 20-3 when scoring four or more runs and 6-15 when scoring three runs or fewer.

TRAINER’S ROOM

Yankees: INF D.J. LeMahieu (left wrist discomfort) said a cortisone shot reduced the pain, but not enough to play. ... 3B Josh Donaldson tested negative for COVID-19 and could rejoin the team during the series.

Rays: RHP Shane Baz (March elbow surgery) allowed two hits in 2 1/3 scoreless innings in his second rehab start for Triple-A Durham on Wednesday night.