ST. PETERSBURG, Fla. (AP) -- The Tampa Bay Rays are trying to make it back to the playoffs for the third consecutive season, and it doesn't look good right now.
Then again, it looked even worse heading into the bottom of the ninth inning Thursday night.
B.J. Upton hit a game-ending, three-run homer off Vicente Padilla, capping Tampa Bay's six-run rally and lifting the Rays to a sorely needed 7-4 victory over the Boston Red Sox on Thursday night.
''That last inning we dug deep and ... it says a lot,'' Upton said. ''We can definitely cash it in, but we're not, and we're going to finish this thing out strong. You never know what's going to happen.''
Tampa Bay salvaged a split of the four-game series and remained 5 1/2 games back of Oakland and Baltimore in the AL wild-card race. The Rays (80-70) have 12 games left on their schedule.
''That was definitely the Rays' magic of old,'' said Matt Joyce, who led off the big inning with a single against Andrew Bailey. ''Hopefully we can muster up a lot more of it in the last couple of games here. Anything is possible.''
Bailey (1-1) gave up four hits and a walk before Padilla came in to face Upton, who drove a 2-1 pitch over the wall in center for his 24th homer. Burke Badenhop (2-2) recorded one out to get the win.
It was only the third victory in 10 games for the Rays, who captured the wild card last season after being nine games behind on Sept. 3.
''We've been missing a little bit of the magic this year, and it doesn't get much more magical than that moment,'' manager Joe Maddon said. ''I've been saying: 'If you believe you can do it, you can; if you don't believe it, you cannot.' We've done it before, we just did it again tonight. I want to believe that's who we are.''
Clay Buchholz outpitched Tampa Bay ace David Price, tossing seven innings of four-hit ball before handing a 2-0 lead to the Boston bullpen. Mauro Gomez hit a two-out RBI triple in the eighth for the Red Sox, but they couldn't hold on for the victory.
Jose Iglesias had three hits for Boston, including his first career home run. Ryan Lavarnway and Gomez each had two hits and an RBI.
Price allowed three runs and eight hits in 7 1-3 innings. He struck out seven and walked one while throwing 119 pitches.
''I felt like (Buchholz) outpitched me,'' Price said. ''But I guess it keeps us in this race so that was a great win for us. We needed to win that game.''
Cody Ross' two-out double in the sixth gave Boston the lead and ended Price's streak of 29 1-3 scoreless innings at home. Lavarnway drove in Ross with a single.
Ben Zobrist drove in the Rays' first run with an eighth-inning sacrifice fly off Junichi Tazawa. It was the Rays' first run in Price's last three starts at home.
Buchholz struck out four and walked two. The right-hander is 0-3 with a 4.07 ERA in his last six starts.
The six-run ninth inning matched a franchise record for the Rays, who had only one run and five hits through the first eight innings.
''Buchholz, obviously, deserved a 'W.' I let him down,'' Bailey said. ''I didn't get ahead of guys, couldn't put guys away, just didn't pitch. There's no excuse. There's nothing I did right that inning.''
NOTES: The eight combined strikeouts by Price and Wade Davis left the Rays with 1,264 for the season, two short of the American League record set by the New York Yankees in 2001. ... With two games left at Boston next week, the Red Sox lead the season series 9-7. ... Red Sox 2B Dustin Pedroia went 0 for 16 in the four-game series. ... The Rays have scored 20 runs in their last two games after producing only 26 in the eight preceding games . . . Lavarnway has seven RBIs in his last seven games.