Longoria socked a solo homer in the first to put the Rays ahead and drew a bases-loaded walk from Jason Berken in the sixth inning to push across the tie-breaking run as Tampa Bay took the rubber match of a three-game series at Camden Yards.
Willie Aybar and Reid Brignac each contributed two hits and an RBI for the victors.
James Shields (8-9) surrendered four runs on eight hits in 6 1/3 innings of work to notch the win, and Rafael Soriano collected his 24th save with a 1-2-3 ninth.
Brian Bergesen (3-8) took the loss, yielding five runs on nine hits over 5 1/3 frames.
Ty Wigginton hit a two-run homer for Baltimore.
Swim Week Miami Beach 2014 [PHOTOS]