MINNEAPOLIS — Max Kepler took one for the team — and wound up with a hop-off winner for the Minnesota Twins.

Kepler was hit by a pitch with the bases loaded and two outs in the bottom of the ninth inning, and the Twins rallied to beat the Chicago White Sox 5-4 Thursday for their fourth straight victory.

Trailing 4-3 entering their final at-bat at Target Field, the Twins came back and held their slim lead for the second AL wild-card spot. They completed a three-game sweep with their first game-ending HBP since current Minnesota manager Paul Molitor was plunked in the 10th at the Metrodome in 1996 to beat Kansas City.

“A win’s a win. It’s a good way to finish a good month for us,” Molitor said.

And nope, Molitor said he didn’t remember that game from 21 years ago.

Finishing with a major league-leading 20 wins in August, Minnesota won 20 games in a month for the 10th time in team history and second time in 25 seasons. The Twins went 20-7 in May 2015.

Pinch-hitter Ehire Adrianza opened the ninth with a single to right off closer Juan Minaya (2-2). After a one-out walk, Eddie Rosario hit a tying single.

Joe Mauer then walked to load the bases and Jorge Polanco lined back to Minaya.

With the crowd on its feet, Minaya’s first pitch hit Kepler in the shin for the winning run. Knocked to the ground, Kepler got up quickly and trotted to first.

“They come in all shapes and forms, but a walk-off’s a walk-off,” Kepler said. “We’ll take it.”

Closer Matt Belisle (1-2) got the win despite giving up the go-ahead run in the top of the ninth.

“It feels like something good’s going to happen and if we don’t win, they got lucky,” Belisle said.

Alen Hanson homered earlier to put the White Sox ahead 4-3.

“Just wasn’t meant to be,” manager Rick Renteria said.

Both starters — Chicago’s Miguel Gonzalez and Minnesota’s Bartolo Colon — allowed three earned runs in six innings. Colon gave up 10 hits and struck out eight; Gonzalez gave up seven hits and fanned five.

Chicago, 4-19 in its last 23 road games, scored three runs on nine hits between the second and fourth innings, but left two runners on in each frame.

An RBI single by Rob Brantly and RBI double by Adam Engel gave Chicago a 2-0 lead in the second. Yolmer Sanchez singled home a run in the fourth for a 3-1 lead.

Polanco and Kepler had RBI doubles in the fifth to tie it at 3.

TWINS SET TEAM RECORDS

Kepler’s double made him the fifth Twins player with at least 20 RBIs in August, the first time that has happened in team history. Rosario (25), Byron Buxton (22), Polanco (22) and Brian Dozier (22) have also reached the mark.

Minnesota pitchers struck out 38 batters in the three-game series, the most in team history.

GONZALEZ GONE?

The deadline for waiver deal trade is Thursday night. Renteria is a bit surprised Gonzalez is still with Chicago considering how well he’s pitched since coming off the disabled list for right shoulder inflammation July 14. In his previous four starts, Gonzalez allowed four earned runs in 28 innings.

“I haven’t been thinking about it, honestly. If something happens, it’s meant to be,” Gonzalez said. “But if it doesn’t, I’m here all the way with the White Sox and just keep grinding.”

ANGRY VARGAS

Twins first baseman Kennys Vargas struck out three times. After leaving a runner stranded at third base in the eighth, Vargas broke his bat in half by slamming it over his knee.

TRAINER’S ROOM

White Sox: 1B Jose Abreu (sore elbow) and SS Tim Anderson (hamstring tweak) missed the game. Both may return Friday.

Twins: Fearing a hamate injury that could have ended his season, an MRI on Buxton’s left hand showed a bone contusion. He didn’t start in CF. … 3B Miguel Sano, out since Aug. 19 with a left shin injury, was to undergo more tests Thursday. … RHP Adalberto Mejia (left arm strain) allowed two hits in three innings at Triple-A Rochester Wednesday. He’s scheduled to start there again Monday and throw 50-60 pitches.

UP NEXT

White Sox: Reynaldo Lopez (0-1, 6.97) is expected to come off the 10-day disabled list (back strain) when Chicago opens a 10-game homestand Friday against Tampa Bay. Blake Snell will start for the Rays (2-6, 4.29).

Twins: Dillon Gee (1-1, 3.53) gets the call for Minnesota against Kansas City’s Jason Hammel (6-10, 4.76) in Friday’s first game of a weekend series.