Starling Marte had four hits and four RBI as the A's snapped a four-game skid. Oakland remained four games behind the Yankees for the second AL wild card, with the Mariners and Blue Jays also in the way.
Matt Olson drove in four runs for Oakland. Chad Pinder added a pinch-hit grand slam in the seventh inning.
"I was just trying to command my pitches, hit my spots," Montas said. "When guys are swinging and you hit your spot, it's going to be tough for them to put a good swing on the ball."
Jose Altuve hit his 30th home run for the Astros. Houston's magic number to clinch the AL West remains three over Seattle.
Astros pitcher Zack Greinke was scratched from his scheduled start and placed on the 10-day injured list with neck soreness. The 2009 AL Cy Young Award winner could return before the playoffs.
"You hate to lose, especially by a large margin," Houston manager Dusty Baker said. "They beat us pretty good tonight."
Two years after serving an 80-game suspension following a positive test for performance-enhancing drugs, Montas (13-9) was dominant while helping the A's stave off elimination in the AL West and preventing the first-place Astros from inching closer to the division title. The right-hander allowed one run, had eight strikeouts, walked three and hit two batters.
"It looked like he was in control most of the game," A's manager Bob Melvin said. "Fantastic to be throwing that hard and be this good toward the end of the season. He had that look in his eye all game today."
Montas had at least one strikeout in every inning and pitched out of a jam in the seventh after giving up a leadoff walk and single. He's the first A's pitcher to have 200 strikeouts since Barry Zito had 205 in 2001.
"That was one of my goals coming into the season," Montas said. "For me to be able to accomplish that is huge. I'm pretty happy right now."
The A's pitcher flashed some nifty glove work in the seventh when he made a behind-the-back grab on Martin Maldonado's comebacker.
"He's one of the best pitchers in this league, plus he fielded his position, which goes unnoticed," Baker said. "He saved himself tonight, not only pitching but on defense, as well."
Yusmeiro Petit and Domingo Acevedo retired three batters apiece to complete the two-hitter.
The Astros scored an unearned run off Montas in the first inning and went up 2-0 on Altuve's leadoff homer in the third.
The A's took the lead with three runs off fill-in starter Brandon Bielak (3-4) in the third, then broke the game open with six runs in the seventh and five in the eighth.
Pinder's home run off Brooks Raley was Oakland's first pinch-hit slam since Scott Sizemore had one against Texas in 2011.
Bielak, primarily a long reliever with one start this season, allowed three runs and four hits in three innings.
Astros: Yordan Alvarez was the DH after being pulled from Wednesday's game and not playing Thursday because of overall soreness. ... RHP Peter Solomon was recalled from Triple-A Sugar Land to take Greinke's spot on the active roster.
Athletics: 2B Josh Harrison left the game after fouling two balls off his left leg in the seventh inning. Harrison finished the at-bat before being taken out in between innings.
Astros LHP Framber Valdez (11-5, 3.07 ERA) has won his last two starts and is looking to make up for a rough one against Oakland in July when he allowed 10 hits and five earned runs in five innings. Athletics LHP Sean Manaea (10-10, 4.05) is winless in four starts against Houston this season.
Pinder bashes grand slam in Athletics' win over the Astros
Chad Pinder crushes a grand slam to left field in the Athletics' big win vs. the Astros.