Derek Holland reached deep into the file of Things That Should Never Happen in the seventh inning Wednesday night.

The left-hander opened the frame by allowing a single that grazed his forearm and then walked the next two batters all while nursing a two-run lead over the worst team in baseball.

Somehow the Texas Rangers emerged with the lead.

Then Tanner Scheppers dipped into the same file an inning later turning in one of the most bizarre innings by a Rangers pitcher in recent memory.

Somehow the Rangers emerged lucky to be tied and then naturally took advantage of the Houston Astros’ bullpen to complete a three-game sweep and add a game to their lead in the American League West.

Elvis Andrus’ bases-loaded sacrifice fly with one out in the ninth scored pinch runner Adam Rosales and sent the Rangers to a 5-4 walk-off win and a 2 1/2-game division lead over Oakland.

Craig Gentry homered scored three runs and made a big catch in the sixth inning as the Rangers beat the Astros for the eighth straight time and improved to 14-2 against them this season.

But what should have been an easy night became a nail-biter late after Holland and Scheppers lost control and nearly lost the game.

“I was tense” manager Ron Washington said. “We just kept battling and things worked out for us in the ninth.”

Gentry’s second homer of the season tied the game at 1-1 to start the Rangers’ third and they would add another run as left fielder Robbie Grossman misplayed an Adrian Beltre single and allowed Ian Kinsler to score from first.

Gentry walked to open the fifth and scored three batters later on a single by Kinsler and the left fielder tracked down a Jose Altuve drive to end the sixth with Astros at first and second.

Holland opened the seventh at 80 pitches before Jason Castro’s single to center grazed Holland’s forearm. He stayed in the game and was ahead of Chris Carter 0-2 before walking him and throwing four straight balls to Matt Dominguez to load the bases.

“I couldn’t settle myself down from being hit” Holland said. “It got me pretty good but I’m fine.”

Joakim Soria entered and the Rangers exchanged a run for a double-play grounder and got out of the inning up 3-2.

Gentry sparked the Rangers again in their half going to second on an error to start the inning and moving to third on a bunt by Leonys Martin. Andrus brought in Gentry with a perfect suicide squeeze and a 4-2 lead.