HOUSTON -- The Astros had the Rays on the ropes, threatening to hand Tampa Bay a fifth straight loss in the thick of a postseason race.
The Rays got themselves right in time to salvage a win. Ji-Man Choi put Tampa Bay ahead with a two-run double in the seventh, Travis d'Arnaud homered and drove in four, and the Rays beat Houston 9-8 to avoid a three-game sweep.
Now Tampa Bay heads home for a pivotal 10-game homestand that starts against the Indians on Friday night.
"We were all pumping each other up the whole game, every lead change, we weren't pouting or anything," d'Arnaud said. "We ended up on top, which was huge."
Astros star Jose Altuve hit a tiebreaking solo leadoff homer in the sixth, his 25th, but Tampa Bay scored three runs in the seventh to make it 8-6. Tommy Pham had an RBI single off Chris Devenski (2-3), and Choi brought in two more with a drive to center.
Houston ended a seven-game winning streak.
"You get a close game like that -- and certainly, a crazy game like that -- you always look back at the opportunities," Astros manager AJ Hinch said. "We didn't play particularly clean, but we did fight and I love the fight. It was a weird back-and-forth game, but we didn't do quite enough at the right times to win the game."
The Rays used seven pitchers, including opener Andrew Kittredge and long man Trevor Richards, who combined to allow four hits and two runs in the first three innings. Jose De Leon (1-0) pitched a scoreless inning, and Emilio Pagan earned his 15th save.
D'Arnaud put Tampa Bay up 4-2 with a two-run homer in the fourth and added an RBI single in the sixth to tie it at 5.
Zack Greinke had won four straight starts since joining Houston prior to the July 31 trade deadline. He got a no decision after allowing five runs and six hits in 5 2/3 innings while striking out eight and walking one.
"I felt pretty good out there, but everyone that got on seemed to score," Greinke said. "And I made a bad pitch for the two-run homer. Everything about it was bad. It's kind of frustrating. I lost the game. I gave up more runs than I would've liked, especially when you're feeling pretty good."
The Astros drew three bases-loaded walks over the fourth and fifth innings to take a 5-4 lead but left the bases loaded in both frames. Houston stranded 11 runners total.
Houston again pulled within one run when Josh Reddick made it 8-7 with an RBI single in the seventh. The Rays answered with a fielder's choice grounder from Meadows to make it 9-7.
Abraham Toro led off the bottom of the ninth with his first career homer to make it 9-8 before the Rays held on. Reddick was ejected in the ninth after arguing a strikeout call.
Rays: OF Kevin Kiermaier (left rib cage contusion) remained out of the lineup for a third consecutive game as Cash said he's still in "a significant amount of pain." Cash said he's optimistic he can avoid the injured list and possibly return Friday. ... RHP Tyler Glasnow (right forearm strain) will begin a rehab assignment Friday and is scheduled to pitch one inning or 20 pitches for Class A Charlotte. Glasnow has been out since May 11.
Astros: RHP Josh James (shoulder) will make what Hinch said he hopes will be his last rehab outing at Triple-A Round Rock. James will be evaluated Friday to see if he needs another rehab outing. . SS Carlos Correa (back) still hasn't begun swinging and will not travel with the team on its upcoming road trip. ... RHP Ryan Pressly (knee) has been doing soft throwing and keeping his arm strength up. Pressly had right knee arthroscopic surgery and is expected to be out four to six weeks. ... Hinch said neither RHP Brad Peacock (shoulder) nor RHP Aaron Sanchez (pectoral) will play catch during the upcoming road trip.
Choi, a first baseman, made a dazzling over-the-shoulder catch in shallow right field to hold Tampa Bay's 8-7 lead. Through a translator, Choi said he was happy to be able to make the critical catch because he was starting to get a cramp in his neck, looking at the ball from an awkward angle.
Rays: No starter has been announced for Friday's series opener at home against Cleveland.
Astros: LHP Wade Miley (13-4, 3.13 ERA) will face the Blue Jays for Friday's season opener in Toronto.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
DJ LeMahieu thrilled to play in front of crowd, knows 'how much it means to a lot of fans to watch the Yankees'
On Sunday, DJ LeMahieu and the New York Yankees will have a chance to feel that "adrenaline and excitement" that last season lacked, when they play in front fans against the Toronto Blue Jays to Steinbrenner Field.
Albert Pujols reiterates he'll decide future after season with Los Angeles Angels
Following last week's misinterpreted Instagram post, Albert Pujols reiterated his stance that he hasn't decided whether to retire after this season
Revisiting Miguel Cabrera's 2020 homers
As Miguel Cabrera attempts to get to 500 career home runs, relive all the dingers he hit during the 2020 season.
Detroit Tigers slugger Miguel Cabrera hopes to reach 500 home runs, 3,000 hits in 2021 season
Tigers star Miguel Cabrera is 13 home runs shy of 500 for his career and 134 hits short of 3,000. He hopes to reach both milestones this season. "We can do both," he said.
Chicago Cubs' Joc Pederson, Javy Baez both have something to prove, but for different reasons
Chicago Cubs shortstop Javy Baez and left fielder Joc Pederson both have something to prove in 2021, but for different reasons.
Los Angeles Angels re-sign veteran right-hander Jesse Chavez to minor league deal
Veteran right-hander Jesse Chavez is re-signing with the Los Angeles Angels on a minor league deal.