ARLINGTON, Texas — The way the Texas Rangers are hitting, they can win even when their best starting pitcher struggles.

Texas rallied from a four-run deficit on Friday night to beat the Oakland Athletics 7-6 on Jonathan Lucroy’s two-run single with two outs in the bottom of the ninth inning.

The Rangers reduced their magic number for clinching the AL West to six after Seattle’s 6-0 loss to Houston.

Lucroy hit a ground ball inside third base to drive in pinch-runners Delino DeShields and Joey Gallo, who had stolen second base when Rougned Odor struck out. Carlos Beltran’s one-out double began the winning rally.

“I had the big hit,” Lucroy said. “Look, I was 1 for 5 and I came up to hit with runners in scoring position. I was able to sneak one past the third baseman.”

Ryan Madson (5-6) had his seventh blown save in 37 chances. He faced five batters, all averaging .280 or better.

“As far as the depth of the lineup and the guys on the bench too, they’re as good as there is in the league, especially with the additions they’ve made,” Oakland manager Bob Melvin said.

The in-season additions included Beltran and Lucroy.

“(Madson) strikes out Odor, who’s a great hitter in big situations,” Melvin said. “There were runners on base, but once he got Odor, I thought we were going to win the game.”

Sam Dyson (2-2), the Rangers’ fourth pitcher, got the win.

Oakland built a 6-2 lead against Cole Hamels on home runs by Khris Davis and Brett Eibner, who drove in four runs.

Davis’ homer was his 38th of the season, his eighth in 14 games against Texas and his third against Hamels in only seven at-bats.

Hamels allowed six earned runs in six innings. In his last four starts, he’s 0-1 with a 10.50 ERA in 18 innings pitched.

Hamels walked three batters. His 75 walks are the most in the American League this season. He has allowed more than three earned runs in three of his last four starts.

“The story of the night is not Cole Hamels,” Rangers manager Jeff Banister said. “The story of the night is that he needed our offense today, and they delivered.”

Texas came back with two runs in the sixth on Adrian Beltre’s double and a run-scoring single by Mitch Moreland. Carlos Gomez, another in-season acquisition, led off the seventh with a homer.

It was the Rangers’ seventh walk-off win this season, and Lucroy’s fifth career game-ending hit. The Rangers lead the major leagues with a franchise-record eight wins when trailing after eight innings.

TRAINER’S ROOM

Rangers: RF Shin-Soo Choo, on the disabled list since Aug. 16 with a broken left forearm, will begin swinging a bat, but no date has been established for his return. … RHP Tony Barnette (strained left oblique) is not expected to pitch until the final week of the season.

ERASING A RUN

Texas had a run taken off the scoreboard in the third inning. With the bases loaded and one out, Ian Desmond hit a slow grounder to shortstop Marcus Semien. Desmond reached first base as Mitch Moreland crossed home plate. However, Desmond was called out because Carlos Gomez slid wide of second base to hit second baseman Joey Wendle.

BELTRAN PASSES GEHRIG

Carlos Beltran’s two doubles gave him 535 for his career, passing Lou Gehrig for 38th in major league history.

UP NEXT

Athletics: Rookie RHP Raul Alcantara (0-1, 7.27) will start the second game of the three-game series on Saturday.

Rangers: RHP Yu Darvish (5-4, 3.28) is scheduled to pitch for Texas Saturday on seven days’ rest.