It marked Longoria's seventh career four-hit game, and first against the Yankees.
Tampa Bay (22-22) returned to the break-even mark after rallying for three runs in the seventh. Logan Morrison tied the game with a bases-loaded sacrifice fly, and Rickie Weeks Jr. came off the bench to deliver a pinch-hit two-run double that bounced under third baseman Ronald Torreyes' glove.
Starlin Castro and Jacoby Ellsbury drove home runs against Rays starter Erasmo Ramirez, who permitted two runs and six hits over 5 1/3 innings in his second start of the year.