The Rays scored six times in the ninth to stay within 5 1/2 games of a wild-card spot in the American League.
With Boston holding a 4-1 lead, Andrew Bailey came on to work the ninth for the Red Sox.
Carlos Pena then singled in Joyce with Keppinger going to third. Rich Thompson ran for Pena and stole second, after which Stephen Vogt walked to load the bases.
Desmond Jennings followed with a single that scored two runs and tied the game. That brought Upton to the plate and he ended the contest with his homer to center on a 2-1 pitch.
The ninth-inning rally made a winner out of Burke Badenhop (2-2), who retired the only batter he faced in the top half of the inning.
Celebrity Breakups and divorces of 2014 [PHOTOS]