Shields (9-8) allowed just one run on six hits and a walk while striking out six.
Evan Longoria went 2-for-2 with a home run and two walks for the Rays, who have still lost six of their last nine.
Kyle Farnsworth hurled a scoreless ninth for his 19th save of the year.
CC Sabathia (14-5) celebrated his 31st birthday with his third complete game of the year, but it was in a losing effort. He allowed the two Rays runs on five hits and four walks. He also struck out eight.
“That’s baseball. It’s unfortunate that we only got one run, but you’re going to lose some games like that during the season,” Yankees manager Joe Girardi said.
Robinson Cano had two hits, including a run-scoring double, for the Yankees, winners in four of their last five entering Thursday’s contest.
Longoria hammered a hanging slider into the left-field bleachers in the first to give the Rays an early 1-0 lead.
Tampa Bay extended its lead in the fifth after Elliot Johnson worked a two-out walk and came around to score on Sam Fuld’s triple into the right-field corner. Fuld was stranded at third, however, as Ben Zobrist struck out to end the frame.
After stranding a man on second in the first inning, New York did not put another man in scoring position until Derek Jeter pulled a one-out double into the left-center gap in the eighth. Shields then got Mark Teixeira to pop out to the left side of the infield, but Cano followed with a double down the first-base line, knocking Shields of the mound.
Brandon Gomes took the bump next and needed just one pitch to induce a Nick Swisher flyout to center field, keeping it a 2-1 game.
“How about [Gomes]? The kid comes in there and throws a first-pitch split and gets us out of there,” said Rays manager Joe Maddon. “He (Swisher) was just a little bit out in front because he was thinking fastball there.”
Farnsworth allowed a one-out single to Russell Martin, putting the tying run on the bases. But fanned Eduardo Nunez on a high fastball and Curtis Granderson on a slider in the dirt to end the game.
New York pitchers had not allowed a home run in eight straight games before Longoria’s homer in the first…Yankees center fielder Granderson did not start the contest after getting hit in the back with a pitch on Wednesday, but he pinch-hit for left fielder Chris Dickerson in the seventh inning and remained in the game at center…New York fell to 27-20 on the road this year…Tampa Bay improved to 4-5 against New York this season.