HOUSTON — Oakland Athletics outfielder Jonny Gomes robbed Chris Carter of an extra-base hit that likely would have given the Houston Astros an early lead on Tuesday night.

After that dazzling defensive play in the fourth inning, however, Carter would have his revenge with a shot that Gomes couldn’t touch.

Carter turned a pitch that missed its location into his 32nd homer, a three-run drive in the eighth inning that gave the Astros a 4-2 win.

Gomes’ biggest regret was that the A’s let the Astros stay within striking distance.

“You want to get some insurance to where a homer won’t decide it,” Gomes said. “Those guys, one through nine, are swinging for the fences. There’s no secret about that. And that’s what got us, two homers.”

Oakland starter Jason Hammel had retired 10 straight batters when he was replaced by Luke Gregerson (3-3) for the eighth inning. Robbie Grossman reached on an error by first baseman Stephen Vogt with one out and Gregerson hit Jose Altuve with a pitch.

Carter then launched a 90 mph fastball onto the tracks atop the wall in left field to put Houston on top. Carter homered for the second straight game and leads the majors with 19 since the start of July.

“I was trying to go sinker, down and away,” Gregerson said. “It started away, but it just ran all the way across the plate, down and in.”

Carter nearly made Hammel pay in the fourth inning before Gomes bailed him out with a diving catch near the left-field warning track to leave two runners stranded for Houston.

“He got all of it, but thank goodness Jonny will go all out to get the ball,” Hammel said. “He’ll run through a brick wall if he has to. As long as we can keep the ball in the yard and give our guys a chance to field it, it’s a way to win ball games.”

Hammel had his best start since joining the Athletics in a trade from the Cubs. He allowed three hits and one run while working on extra rest — the A’s skipped his last turn because they had two off-days last week.

Josh Fields (4-6) pitched a scoreless eighth for the win and Chad Qualls did the same in the ninth for his 15th save.

The A’s began the day tied with the Angels for the AL West lead.

Dexter Fowler hit a solo homer for Houston to cut the lead to one in the fourth inning.

Dallas Keuchel allowed five hits and two runs in seven innings to remain winless since July 30, a span of five starts.

In addition to his defensive effort, Gomes gave the Athletics a 1-0 lead with an RBI single with two outs in the first. He later singled in the Oakland fourth and scored on a double by Nate Freiman to push the lead to 2-0.