OAKLAND, Calif. — The Houston Astros remain in the thick of the AL wild-card race, thanks to a pair of big swings from Evan Gattis and a clutch throw by catcher Jason Castro.

Gattis homered twice, Castro threw out a runner to end the game and the contending Astros beat the Oakland Athletics 6-5 on Wednesday to complete a sweep.

"Just trying to finish strong," said Gattis, speaking both of himself and the Astros. "You don't want to limp out of the season. You kind of want to sprint, you know?"

Houston has been sprinting ever since a 1-6 stretch that ended Sept. 13.

The Astros, who began the day two games behind Baltimore for the second AL wild-card spot, have won five of six since then.

They had to sweat out their latest win after giving up an unearned run in the ninth.

Oakland scored on second baseman Jose Altuve's fielding error with two outs 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.

"I don't think (Alcantara) got his best jump on that one but that's what he's in there for and Castro made a good throw," A's manager Bob Melvin 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 former A's setup man Luke Gregerson retiring three batters for his 15th save.

"We just need to beat the teams that we should beat, and I think this is one of them," Gregerson said. "We need to keep winning, keep us in the wild card and hopefully keep getting bumped up."

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

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 finish the three-game sweep.

"Really just trying to stay inside the ball and behind it instead of trying to come around," Gattis said. "There are a lot more outs at the end of the bat."

The Astros scored their first run without a hit in the fifth 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 centre 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.

SEPTEMBER STRONG

McHugh won for the third time in four starts this month and improved to 11-0 in September since 2014.

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

Astros: RHP Mike Fiers (11-7) faces the Angels in Anaheim on Thursday in the opener of a four-game series. Fiers has a 4.06 ERA over his previous 19 starts.

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