ST. PETERSBURG, Fla. — If the Yankees still held out any hope of clawing their way back into playoff contention after three straight losses, those dreams ended when they woke up Sunday morning to the news that All-Star reliever Andrew Miller had been dealt to Cleveland for four prospects.

There was an unmistakable pall over the clubhouse as the Yankees arrived for their series finale at Tropicana Field against the last-place Rays. Coming on the heels of last Monday’s trade of closer Aroldis Chapman, it was a clear sign from management that this season likely is a lost cause.

“We didn’t play good enough,” catcher Brian McCann said in a quiet voice. “We needed to win, and we didn’t do it.”

McCann acknowledged the stunning nature of a selloff by such a traditional power team as the Yankees. “It doesn’t happen,” he said. “I know it’s the first time this organization has done it in a long time.”

Not surprisingly, given the emotional gut punch they absorbed, the Yankees couldn’t avoid being swept by the lowly Rays, who punched them in the mouth again, 5-3. If there was a bright spot for the Yankees, it was Carlos Beltran’s two-run homer in the sixth, but that was only because it raised the value of their biggest remaining asset before Monday’s 4 p.m. non-waiver trade deadline.

If they’re going to tear it down, might as well take it down to the foundation. Selling off at the trade deadline has been unthinkable for decades, but under the circumstances with this aging team, management recognized the inevitable need to act for the future.

Third baseman Chase Headley endured similar circumstances when he was with the San Diego Padres, but it was a far cry from his expectations when he joined the Yankees. “I came here to try to win a championship,” he said. “That was my expectations coming here. Obviously, the way the team has performed up to this date — I don’t want to say has made this happen — but it’s obviously a large part of why this has happened. We just haven’t played well enough.

“The biggest strength we had was the back end of the bullpen. We’re probably not as good a team as we were 10 days ago, seven days ago. But again, that’s out of our control.”

Weak hitting and a propensity to give up home runs to the Rays haunted the Yankees again Sunday. Rays starter Blake Snell (3-4) had a career-high nine strikeouts in 5 1⁄3 innings, and the Yankees fanned a total of 13 times.

Yankees starter Michael Pineda (5-10) struck out eight in six innings, but he allowed two runs in the fourth and then a towering home run by Brad Miller in the fifth that landed in an aquarium in right-center among the manta rays to give the human Rays a 3-0 lead. It was the Rays’ seventh homer in the three-game series.

After Jacoby Ellsbury drew a leadoff walk from Snell in the sixth, Beltran unloaded his 22nd home run into the seats in left-center to cut the deficit to 3-2. But Pineda loaded the bases in the bottom of the sixth, including an intentional walk to get to No. 9 hitter Luke Maile. Typical of the way things have gone for the Yankees, Maile delivered a two-out, two-run single for a 5-2 lead.

The Yankees added a run in the eighth on McCann’s RBI single, but in the ninth, Alex Colome got pinch hitter Mark Teixeira to ground out and struck out pinch hitter Alex Rodriguez before whiffing Brett Gardner for the final out. It was the fifth straight strikeout for Rodriguez, who fanned four times Saturday night.

Reflecting on the trades and the losing streak heading to the deadline, Rodriguez said, “We have no one to blame but ourselves. We knew what was at stake, and we just haven’t gotten it done . . . Our offense hasn’t played to our potential, and I haven’t played to my potential this year. It’s been extremely disappointing.”