ST. PETERSBURG, Fla. — Jake Odorizzi made few mistakes over the first 6 1⁄3 innings Sunday.

Starlin Castro made him pay for his biggest one.

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

Castro’s two-run blast completely 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.”

Since baseball.reference.com data is available (1913), Sunday marked the second time the Yankees won with one hit, the other time July 10, 1914, against Cleveland.

“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.”

Before Castro stepped to the plate, Odorizzi walked Gardner — who had fallen behind 1-and-2 — just 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 on a grounder.

The big arms at the back of the Yankees bullpen made quick work of the Rays after the Castro blast, with Dellin Betances, Andrew Miller and Aroldis Chapman combining for three perfect innings.

“The type of bullpen we’ve got,” Castro said of his thought following the homer, “it’s almost game-over.”

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

As Gardner referenced, the Yankees (24-25), who won two of three here and start a three-game series against the Blue Jays Monday night in Toronto, received another terrific outing from Eovaldi.

The righthander, 5-0 with a 2.92 ERA over his previous six starts, allowed one run and six hits over six innings in improving to 6-2, 3.71.

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) allowed two runs and one hit in seven innings. He struck out six and walked one.

The Rays (22-26) put the game’s first runner in scoring position in the third and took the lead. Leadoff man Brandon Guyer smoked a grounder up the middle that Castro made a diving stop to his right on but could not secure. Guyer moved to second on Miller’s grounder and to third on a wild pitch. Evan Longoria, who had four RBIs Saturday, then dumped a 1-and-1 slider to right for a single to make it 1-0. It gave the third baseman 90 RBIs vs. the Yankees since his rookie year in 2008, the most in the majors against the Yankees in that time.

Eovaldi won, barely, his biggest battle against Longoria, getting him to fly to the wall in right with two runners on to end the fifth.

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