He was a double shy when he came to the plate with two outs in the ninth inning and laced a laser to left field. Longoria dashed to second base and slid in to avoid the tag of Jose Altuve.
He was initially ruled out, but the call was overturned after a crew chief review. Most of the Rays stood up behind the railing of the dugout and cheered as the call was reversed, and Longoria flashed a big smile knowing that he joined Melvin (then known as B.J.) Upton as the only Rays to achieve the feat.
Logan Morrison hit a solo homer and finished with two RBIs as the Rays bounced back after losing Monday's opener 14-7.
Lucas Duda singled with one out in the first before Longoria launched his towering homer, which banged on train tracks atop left field, off Mike Fiers (7-6) to make it 2-0. Morrison's 27th homer came next to make it 3-0.
Rays starter Chris Archer (8-6) allowed six hits, four runs and struck out five in 6-plus innings to get his first win since July 4 and improve to 5-2 in eight career starts against the Astros. Alex Colome pitched a perfect ninth for his 31st save.
Duda doubled with one out in the third before scoring on Longoria's first triple of the season to push the lead to 4-0. Longoria then scored on a two-out single by Adeiny Hechavarria.
Archer had allowed just one hit when Carlos Beltran sent a 96 mph fastball into the seats in right field with one out in the fifth to cut the lead to 5-1. He retired Evan Gattis before Alex Bregman's solo shot to left field got Houston within 5-2.
Reymin Guduan took over for Fiers with one out and one on in the seventh and allowed consecutive singles to Longoria and Morrison with two outs to send another run home to make it 6-2.
Marwin Gonzalez doubled with no outs in the seventh before an RBI single by Beltran ended Archer's night. Steve Cishek was greeted by a double from Gattis before Beltran scored on a groundout by Bregman to cut the lead to 6-4.
The Astros had runners at first and third after a walk by Derek Fisher with two outs in the inning, but Tommy Hunter took over and retired Altuve to end the threat.
Fiers yielded eight hits and six runs in 6 1/3 innings for his second straight loss.
Rays: OF Steven Souza Jr. was scratched from the lineup about an hour before the game of a bruised left foot. Souza was injured on Monday night when he fouled a ball off his foot. ... CF Kevin Kiermaier, who has been on the disabled list since June 9 after fracturing his right hip, has had a setback in his rehabilitation. The outfielder has been shut down from baseball activities for the rest of the week after experiencing pain while bending down to field grounders. Manager Kevin Cash doesn't think this is a serious problem but it will likely keep him out past Aug. 8, when he's eligible to come off the 60-day disabled list.
Astros: SS Carlos Correa resumed activity on Tuesday for the first time since tearing a ligament in his left thumb on July 17. The All-Star is expected to be out at least one more month with the injury which required surgery, but did some sprints and conditioning on Tuesday. ... Houston placed relievers Michael Feliz (right shoulder discomfort) and Tony Sipp (right calf soreness) on the 10-day DL on Tuesday. ... INF Colin Moran had surgery on Monday to repair facial fractures he suffered after fouling a ball off his face on July 22.
Rays: Austin Pruitt (5-2, 6.63 ERA) will start for Tampa on Wednesday. He allowed five hits and four runs in five innings with a career-high seven strikeouts in a 6-1 loss to the Yankees in his last start.
Astros: Dallas Keuchel (9-0, 1.94) is scheduled to start for Houston on Wednesday. The left-hander allowed six hits and three runs in three innings in a 6-5 win over the Tigers in his return after missing almost two months on the disabled list with a pinched nerve in his neck.