OAKLAND, Calif. — Daniel Mengden threw the pitch exactly where he wanted. Where it wound up — not what the Oakland rookie wanted.

Evan Gattis homered twice, catcher Jason Castro threw out a runner to end the game and the contending Houston Astros beat the Athletics 6-5 Wednesday to finish off a sweep.

The Astros began the day two games behind Baltimore for the second AL wild-card spot.

Gattis reached 30 homers. He hit a two-run drive in the sixth off Mengden (2-8) for a 4-1 lead and connected again in the eighth.

Gattis tagged a 1-2 curveball at his knees on the outer part of the plate, highlighting a three-run inning that gave the Astros a 4-1 lead.

“I thought I made a pretty good pitch but he made a pretty good swing and it went out,” Mengden said.

Gattis’ first homer on the day followed Carlos Correa’s run-scoring double.

“I think the one bad pitch (Mengden) made was the two-strike pitch to Correa,” A’s manager Bob Melvin said. “The pitch to Gattis was a good pitch, it was almost on the ground. You have to give Gattis credit there.”

Oakland scored on second baseman Jose Altuve’s fielding error with two outs in the ninth inning to pull within 6-5. Castro then threw out pinch runner Arismendy Alcantara trying to steal second, and the call was upheld on a replay review.

“That replay on the stolen base was a tough one,” Melvin said. “(Astros reliever Luke Gregerson) is a pretty easy guy to steal on for the most part. I don’t think (Arismendy) got his best jump on that one but that’s what he’s in there for and Castro made a good throw.

“There are a lot of plays in this game that were just a couple of inches one way or the other and if we get them we’re probably talking about a different game right now, but we didn’t and they won the game,” he said.

Collin McHugh (12-10) won his fifth straight decision, allowing two runs and six hits over 5 2-3 innings. Five relievers combined to record the final 10 outs, with Gregerson retiring three batters for his 15th save.

Carlos Correa had two hits, including an RBI double, and Altuve singled twice and scored a run. Gattis homered for third time in three days to complete the three-game sweep.

The Astros scored their first run without a hit in the fifth inning and added three more in the sixth.

Altuve, the AL’s leading hitter, had a one-out single and scored the go-ahead run on Correa’s double. Gattis followed with a home run.

Gattis’ homer in the eighth was a towering shot that hit off the façade underneath the luxury suites in center field.

Danny Valencia singled and scored twice for the A’s. Oakland has lost the first three games on its final homestand after an impressive 6-1 road trip.

MENGDEN WEARS DOWN

Mengden needed only 26 pitches to get through the first three innings and didn’t give up a hit until Yuli Gurriel’s one-out single in the fourth before things quickly unraveled. He allowed four runs over 5 2-3 innings with seven strikeouts and two walks.

TRAINER’S ROOM

Astros: OF Colby Rasmus missed his third straight game because of “a lot of different” physical issues, according to manager A.J. Hinch. Rasmus missed 23 games earlier this season after undergoing surgery to remove a cyst in his right ear. … Preston Tucker was scheduled to undergo season-ending surgery on his right shoulder Wednesday and the team is confident the outfielder will be healed in time for spring training.

Athletics: OF Khris Davis missed his second straight game after being a late scratch Tuesday because of an illness. … Reliever J.B. Wendelken will seek a second opinion on his right elbow but Melvin indicated it’s likely Wendelken will undergo Tommy John surgery.

UP NEXT

Athletics: Kendall Graveman (10-10) starts against Texas on Friday at the Coliseum. The right-hander is winless since Aug. 24.