ST. PETERSBURG, Fla. — Jake Odorizzi made few mistakes against the Yankees in the first 6 1/3 innings Sunday — maybe none. Then he made one, and Starlin Castro made him pay.

The Rays righthander took a no-hitter into the seventh inning and got the first out but then grooved a belt-high fastball on a 1-and-0 count that the Yankees second baseman didn’t miss.

Castro’s two-run blast to left-center turned the afternoon around for the Yankees and allowed them to escape Tropicana Field with a 2-1 victory in front of 19,748, a game in which they managed just that one hit.

“He was doing a great job today, making good pitches, all of his pitches,” Castro said. “I was just looking for one pitch that I could drive, and that’s what happened.”

It was the first time in nearly 102 years that the Yankees won with one hit. The other time was Game 2 of a doubleheader at the Polo Grounds on July 10, 1914, against the Cleveland Naps. That game went only 5 1⁄2 innings.

“I don’t really want to say we stole one,” Brett Gardner said. “I think that with the way that Odorizzi pitched and the way [Nathan] Eovaldi pitched, somebody’s obviously going to lose the game and not feel good about it. Thank goodness Starlin came through in a big spot.”

advertisement | advertise on newsday

Before Castro stepped to the plate, Odorizzi walked Gardner, who had fallen behind 1-and-2. He was only the second Yankee to reach base. Dustin Ackley was the first, breaking up a perfect game when he reached on a questionable error charged to Rays shortstop Brad Miller with one out in the sixth.

The big arms at the back of the Yankees’ bullpen made quick work of the Rays after Castro’s blast, with Dellin Betances, Andrew Miller and Aroldis Chapman combining for three perfect innings in which they struck out seven.

Castro’s thought after the home run? “The type of bullpen we’ve got,” he said, “it’s almost game-over.”

Betances struck out two in the seventh, Miller fanned all three in the eighth and Chapman struck out two in the ninth for his seventh save in seven tries.

The Yankees (24-25), who won two of three here and start a three-game series against the Blue Jays on Monday night in Toronto, received another terrific outing from Eovaldi (6-2, 3.71), who is 3-0 with a 1.00 ERA and 0.78 WHIP in his last three starts. He allowed one run and six hits in six innings and is 6-0 with a 2.72 ERA in his last seven starts.

Yankees videos

Eovaldi, who struck out seven and walked two, stranded eight and limited the Rays to 1-for-6 with runners in scoring position, which proved critical.

“I feel like I have the command of my off-speed pitches where I can get out of those situations,” said Eovaldi, who felt especially good about his slider.

Odorizzi (2-3, 3.36) allowed two runs and the one hit in seven innings. He struck out six and walked one.

The Rays (22-26) took the lead in the third inning. With one out, Brandon Guyer smoked a grounder up the middle that Castro stopped with a dive to his right but could not secure. Guyer moved to second on Miller’s grounder and to third on a wild pitch before Evan Longoria dumped a slider into rightfield for an RBI single and a 1-0 lead. It gave the third baseman 90 RBIs against the Yankees since his rookie year in 2008, the most in the majors against the Yankees in that time.

Eovaldi won — albeit barely — his biggest battle against Longoria in the fifth. With runners on second and third and one out, he retired Miller on a fly to left and got Longoria to fly to the wall in right. He also pitched out of a bases-loaded, two-out situation in the sixth.

advertisement | advertise on newsday

“You don’t want to see a performance like that get wasted,” Gardner said of Eovaldi, who still was throwing 100 mph in the sixth. “We’ve already wasted a couple like that this year.”