MINNEAPOLIS (KFGO) — Jonathan Hernández walked three batters in the 13th inning, among a season-high 10 walks by Texas pitchers, and the Rangers dropped out of first place in the AL West for the first time since early April with a 7-6 loss to the Minnesota Twins on Sunday.

Texas wasted a 5-0 lead built with Jonah Heim’s grand slam and J.P. Martinez solo homer, and Royce Lewis started Minnesota’s comeback with a sixth-inning slam.

The Rangers had held a share of first place in every day of the season except when they fell one game behind the Los Angeles Angels on April 8. Texas (73-57) has lost nine of its last 10 games, falling behind Seattle (74-56).

“We’ve got a lot of baseball to play this last month. Whoever plays the best baseball will be playing at the end. That’s the way I look at it,” Marcus Semien said.

Minnesota overcame a 5-4 deficit in the ninth when Aroldis Chapman walked Michael A. Taylor with one out, and Taylor advanced on a disengagement violation. Donovan Solano followed with an RBI single, Chapman’s fifth blown save in eight chances.

Corey Seager hit a sacrifice fly in the 12th but Jorge Polanco hit into a run-scoring forceout in the bottom half.

With Carlos Correa on second as the automatic runner, Hernández (1-2) walked Joey Gallo on four pitches, Matt Wallner on a full count and Taylor on four pitches. The Twins won on a walk-off walk for the first time in exactly a year, since last Aug. 27 against San Francisco.

Hernández threw just eight of 23 pitches for strikes.

“During this little tough streak, there’s been a lot of walks involved. Unfortunately, they come back to get us and then we had the violation and that hurt too,” Texas manager Bruce Bochy said.

Dylan Floro (5-6) got three straight outs after a leadoff walk in the 13th.

Lewis’s slam off Chris Stratton started the comeback for AL Central leader Minnesota, which took three of four in the series and has a six-game lead over second-place Cleveland. Lewis’ only previous slam was May 13 last year.

“I had chills after the game. I was so impressed with our group,” Twins manager Rocco Baldelli said.

Texas starter Jordan Montgomery pitched five shutout innings, then left with the bases loaded.

Heim was hitless in 13 at-bats before his fourth-inning homer against Bailey Ober landed in the flower pots above the right-field wall. His other slam was against the Los Angeles Angels’ Shohei Ohtani on April 14 last year.

Martinez hit his first big league homer for Texas in the second.