Longoria's second-inning blast erased a 2-1 deficit and put the Rays ahead to stay.
Burke Badenhop (3-2) relieved ineffective starter Matt Moore and tossed 1 1/3 innings of scoreless relief to get the victory for Tampa Bay, which kept its slim playoff hopes alive.
The Rays pulled to within 3 1/2 games of the Oakland Athletics for the second American League wild card spot with the win.
Toronto starter Brandon Morrow (8-7) lasted only four innings, allowing five runs on five hits and four walks.
Adam Lind knocked in three runs for the Blue Jays.