The Rays roughed up starter Andy Pettitte and totaled 14 hits. They scored in six different innings and fought off a would-be New York comeback with a three-run eighth that featured Longoria's second home run as well as a two-run blast from Yunel Escobar.
Longoria also homered in the sixth off Pettitte to give the Rays a 4-0 lead and he had a sacrifice fly during Tampa Bay's two-run third.
The win went to Matt Moore (9-3), who blanked the Yankees for five innings, but eventually gave up three runs on four hits over 6 1/3.
Pettitte (5-5) surrendered five runs on nine hits in 6 2/3. He had given up a season-worst 11 hits during his previous outing, in which he suffered a 5-4 loss to the Los Angeles Angels.