Elvis Andrus hit a sacrifice fly to score pinch-runner Adam Rosales with the decisive run in the ninth inning to boost the red-hot Texas Rangers to a 5-4 triumph over the Houston Astros.

Andrus also put down a successful squeeze bunt in the seventh inning, before the Astros tied it in the eighth thanks to the wildness of Tanner Scheppers, who hit a pair of batters and uncorked two wild pitches.

The AL West leaders, who hold a 2 1/2-game advantage on Oakland in the division, have won 18 of their last 22 contests. Texas also has won 14 of the last 15 matchups against the Astros, including this three-game sweep.

Mitch Moreland singled to center to start the bottom of the ninth against Chia-Jen Lo (0-1). Jurickson Profar walked and with one out, Leonys Martin walked. Andrus then lifted a fly ball to left field. The throw home sailed over the head of catcher Jason Castro.

"We wanted to make certain to make him throw strikes. The guy's got good velocity and if you chase the fastball you won't have any success," Rangers manager Ron Washington said of attacking Lo, who recorded his first major league decision.

Craig Gentry homered for the Rangers, who got six-plus innings out of starter Derek Holland. Joe Nathan (4-2) had a pair of strikeouts in the top of the ninth inning.

Castro went 2-for-3 with a homer and scored three times, but the Astros fell to 5-15 this month. Erik Bedard allowed five hits and three runs -- two earned -- over the first 4 1/3 innings.

"It's always tough," Castro said of the loss. "We did a good job rallying back to get back into that game. Obviously that's not how you want to see it end, but we still try to take as many positives as we can."

Castro homered to right field leading off the second inning, but Gentry went deep to left-center to start the bottom of the third. Adrian Beltre singled down the left-field line to plate Ian Kinsler later in the inning.

Kinsler's line base hit to center scored Gentry in the fifth, and Gentry made a spectacular catch to end the next frame. With men on first and second, Jose Altuve hit a ball destined for the wall in left field, but Gentry, nearing the scoreboard, made a leaping grab.

The Astros loaded the bases in the seventh, but got just one run. Joakim Soria retired Max Stassi on a double-play ball, but that scored Castro.

Gentry reached first on Marwin Gonzalez's throwing error in the bottom of the seventh, went to third on a sacrifice bunt and raced home when Andrus bunted a 3-0 pitch toward the mound.

Scheppers put men on first and third in the eighth and then Chris Carter singled in Altuve. Then came back-to-back plunkings of hitters Matt Dominguez and Stassi, who left the contest after being pegged in the face. Stassi's hit-by-pitch scored Castro.

Jason Frasor replaced Scheppers and fanned Brett Wallace with the bases full to keep the game tied.

Game Notes

Houston outfielder Robbie Grossman has a nine-game hitting streak ... Castro's 15 homers this season are the most by an Astros catcher since 1977 ... The Rangers hit the road for the next six games, starting Friday against the White Sox before three more in Seattle.