The Twins had one foot in the clubhouse Friday night. Fans were ready for the scheduled postgame fireworks.

Then it all unraveled in the ninth with Glen Perkins, of all pitchers, on the mound.

Fortunately for the Twins, Brian Dozier has come into his own, and he was there Friday to untangle the Twins from a big mess.

Chicago scored twice off Perkins in the ninth to tie the score, and more runs were coming before Dozier began a huge inning-ending double play. Then Dozier stroked a two-out RBI single in the bottom of the ninth, scoring Eduardo Escobar from second with the winning run in a 5-4 victory over the White Sox.

Perkins retired the first batter he faced in the ninth, but Dayan Viciedo hit a deep fly to left that was misplayed by Josh Willingham into a triple. That was the first of four consecutive hits off Perkins that scored two runs to tie the score.

Manager Ron Gardenhire had Perkins walk Gordon Beckham intentionally to load the bases for Chicago’s No. 3 hitter, Conor Gillaspie. And Jose Abreu, who hit his 21st homer of the season in the first inning, was on deck.

“I don’t ever really like to walk anybody and force [Perkins] to do that,” Gardenhire said, “but I felt we had to go that way and take a shot.”

It was up to his infielders, playing halfway, to make the right read. Go for two or the safer force play at home? Gillaspie put that decision in Dozier’s hands with a ground ball to his left.

“My first step was to go home because it bounced so high,” Dozier said. “Then it was to my left just a tad. Something clicked to stay back on it and turn and throw it.”

Shortstop Danny Santana caught the throw at second and needed all of his strong arm to throw Gillaspie out at first to end the inning. Twins players bounced into the dugout pumping their fists.

Escobar and Sam Fuld drew one-out walks in the bottom of the ninth off Daniel Webb (4-1). Scott Downs entered and got Santana to line out to left for the second out. White Sox manager Robin Ventura replaced Downs with his closer, Ronald Belisario, to face Dozier.

Dozier got a pitch up in the zone and singled to left. Escobar was waved home and slid in ahead of Adrian Nieto’s tag.

The Twins celebrated. Ventura argued that Escobar missed the plate. Gardenhire ran out and argued that Nieto illegally blocked the plate, anyway.

Replays showed that Escobar touched the plate. Game over. Twins win the first two games of the series.

“I would have had an issue if they had called it [out],” Gardenhire said. “I would have been up in the pressbox with you.”

Beckham and Abreu homered off of Ricky Nolasco in the first inning to give Chicago the early lead. The Twins scored three runs in the second, two coming on a bases-loaded double by Escobar. Kurt Suzuki made it 4-2 with a RBI single in the third.

Nolasco lasted only 5⅓ innings, but the bullpen relay worked before Perkins (3-0) blew his third save in 21 tries. But Dozier stepped up with his defense and his bat to put things back in order.

“The walk-off hit, it is what it is,” Dozier said, “but [the double play] was one of the best feelings I’ve had in a while.”