Along with closing in on Texas with a week left in the regular season, the Astros held their lead for the second AL wild card spot. They began the day a half-game ahead of the Los Angeles Angels, and stayed 1 1/2 games in front of Minnesota.
Keuchel (19-8) struck out 10, giving up just one run and two hits in seven innings. The lefty retired 15 straight batters after walking Elvis Andrus in the second inning.
Luke Gregerson threw a perfect ninth for his 29th save.
Martin Perez (3-6) allowed two runs — both unearned — and five hits in six innings.
Keuchel has allowed two runs over his last two starts after giving up nine in 4 2-3 innings against Texas on Sept. 16.
Keuchel set a team record for most strikeouts by a left-hander in a season when he fanned Mike Napoli in the first. Keuchel has 213 this year; Mike Cuellar fanned 203 in 1967.
Pinch-runner Carlos Gomez stole second and later scored on a passed ball in the eighth to extend the Astros' lead to 4-2.
Prince Fielder put the Rangers up 1-0 in the first with an RBI groundout.
Perez retired 11 straight from the second until the sixth, snapped by Carlos Correa's single with one out in the sixth. He rebounded after allowing five runs in four innings in his last start against Oakland.
Astros: Gomez, who had missed the last two weeks with a left intercostal strain, took more aggressive swings Sunday and will work out on the field before Houston's game Monday in Seattle, manager A.J. Hinch said. "We hope that early in the next series he can test it out in a game," Hinch said.
Rangers: RHP Colby Lewis (17-8) takes the mound Monday as Texas starts a three-game series against Detroit. He has won his last three starts and needs four innings to pass 200 innings for the season.
Astros: RHP Lance McCullers (5-7) starts the first game of the three-game series at Seattle on Monday. He is winless in his last seven starts dating back to July 29 and is 0-2 with a 3.24 ERA in four September outings.