Houston snapped a five-game skid with Carter accounting for all of the Astros' runs.
He hit a solo homer in the second that forged a 1-1 tie and then launched a three-run shot in the seventh inning off reliever Jake McGee.
Houston starter Bud Norris (6-7) gave up a run on six hits in seven innings to pick up the victory. It was his first win since June 1.
Jose Veras allowed a hit in the ninth while earning his 17th save.
Tampa Bay had won its previous four games. The loss went to starter Roberto Hernandez (4-10), who put the go-ahead run on base before McGee surrendered the deciding home run by Carter.
Carter has 17 home runs for the year.
Exploding whale video goes viral on Internet
Texas principal bans speaking Spanish, stirs controversy