The Rays, who led 6-2 for most the game, coughed up the advantage in the seventh when San Diego scored five times.
But as they got down to their last out in the ninth, the Rays began a comeback when Ben Zobrist drew a walk from closer Huston Street (0-2).
That brought up Longoria, who launched a pitch onto the porch beyond the left-center field wall, pulling out a dramatic win for the Rays.
Cesar Ramos (1-0) collected the decision with 2 1/3 innings of scoreless relief.
Ray Rice could return to the NFL within a month
UPI horse racing weekend preview