Shields (15-10) posted his fourth victory in a row, scattering seven hits and one run, fanning five with three walks over 8 1/3 innings.
"It's one game at a time, absolutely, but at this time of year, with the circumstances and what we're playing for right now, we needed to do what we just did," said Rays manager Joe Maddon. "Confidence should be derived from that, it was a message sent."
Marco Scutaro's homer was the lone offense for the Red Sox, who skidded to their fifth straight loss and seventh in eight.
Jon Lester (15-7) lasted just four frames, charged with eight hits and four runs to suffer his first loss in a month.
Boston's lead in the wild-card race over Tampa Bay shrunk to 3 1/2 games.
The Rays turned a three-run lead into a seven-run bulge in the fifth. Michael Bowden subbed for Lester, but loaded the bases on walks to Casey Kotchman and Desmond Jennings around a Jose Lobaton single. Matt Albers got the call with two down, but served up a grand slam to Upton which put the home team ahead 8-1.
Shields allowed a one-out walk to Darnell McDonald in the ninth, then was pulled for Dane De La Rosa. He fanned Ryan Lavarnway and induced a game-ending fly out from Scutaro.
Tampa picked up three runs in the first. Desmond Jennings and Upton both singled, Longoria walked and Zobrist plated two on a base hit. Johnny Damon grounded into a fielder's choice to put runners on the corners and a Rodriguez sacrifice fly brought in Longoria.
Scutaro's leadoff homer in the third put the Sox on the board, but Damon started the home half with a triple and scored when Rodriguez followed with a double to make it 4-1.
"Uncharacteristically, he just scattered balls, and by the pitch count you could tell how hard they made him work," said Red Sox manager Terry Francona of Lester, who threw 111 pitches. "It was just uncomfortable. That's just a lot."
Tampa Bay has won nine of 14 meetings from Boston this season, with one more series to play, a four-gamer at Fenway, from September 15-18...Upton scored three times and Jennings came in twice...Sox center fielder Jacoby Ellsbury celebrated his 28th birthday by extending his hit streak to 16 games...Prior to the game, the Rays selected the contract of utilityman Russ Canzler, recalled De La Rosa from Triple-A Durham and designated pitcher Mike Ekstrom for assignment...Lester only gave up four earned runs in his previous five starts.