The Rays were trailing 4-2 in the seventh but rallied for the tying runs when Jose Lobaton and Ben Zobrist got aboard with two outs and Wil Myers lofted a short fly ball to right that eluded a diving try by the Orioles' Alexi Casilla.
Casilla had caught the ball, but it popped out of his glove as he collided with right fielder Nick Markakis. Casilla was shaken up on the play but stayed in the game.
Then in the ninth, Loney led off against Tommy Hunter (6-5) by lining a pitch that just cleared the wall in the right-field corner for the decisive blow.
Joel Peralta (3-8) was credited with the decision for Tampa Bay, which came into the contest with a half-game lead over Cleveland for the first American League wild-card spot with six games remaining.
The Orioles lost third baseman Manny Machado to a gruesome leg injury in the seventh inning.
Exploding whale video goes viral on Internet
Benedict Cumberbatch's dramatic reading of R. Kelly lyrics is just what you need