Sonny Gray retired the first 16 batters he faced Saturday night, mowed through the Pirates with a nine-pitch, a seven-pitch and a six-pitch inning, and had the Target Field crowd believing they were witnessing a perfect game.

And he was arguably outpitched.

Gray's periodic habit of dominating for several innings only to suffer through one rough inning foiled his bid at history. Meanwhile, Pirates righthander Mitch Keller took advantage of baseball's swing-happiest team, racking up a dozen strikeouts — including three straight with the bases loaded — and led Pittsburgh to an ultimately lopsided 7-4 victory over the Twins.

"It felt like a game that kind of slipped away," manager Rocco Baldelli said. "We got on the board [and] Sonny is pitching great. When your starter is pitching that well, you want to win that game. There were a few ways we could have."

The Guardians' loss to Detroit maintained the Twins' AL Central lead at five games, but it was a disheartening finish to a night that started so promising.

Gray opened the game with a nine-pitch, nine-strike first inning, missing back-to-back-to-back strikeouts only when Andrew McCutchen poked the final pitch of the inning, a sweeper across the middle, to Max Kepler in right field.

The veteran righthander appeared in complete control for five spotless innings, inducing routine fly balls and weak grounders. He struck out seven, five of them on three pitches, and needed just 47 pitches to get through five innings.

"I felt good. I felt like I was executing. On the attack and I was moving my fastball around," said Gray, who fell to 6-6 despite a 3.15 ERA. "It just kind of got away from me there a little bit."

Shockingly so. As the announced crowd of 23,822 sensed that Gray might make history, it all unraveled. In fact, after recording 16 outs in a row, Gray allowed seven of the final 11 batters he faced to reach base via hit or walk, four of them scoring.

It began innocently, if disappointingly, enough. With one out in the sixth, Pirates shortstop Liover Peguero poked a first-pitch sinker toward third base. Jorge Polanco charged it, grabbed the ball on its third bounce and rushed a throw to first base. The ball sailed past Donovan Solano as Peguero arrived at the bag, and he took second. Baldelli urged umpire Laz Diaz to rule that Peguero was out of the running lane, but Diaz disagreed.

When the "1" appeared in the scoreboard's hits column, the fans booed official scorer Kyle Traynor.

"You're aware of what's happening," Gray said of his perfect 5â…“ innings. "When [Peguero] hit the dribbler to third, that was fine. Mentally, it didn't stay with me. I never thought, 'Aah, man,' at all. It just kind of got away from us there a little bit."

Catcher Jason Delay followed with a clean single, a sinking liner to center, and second baseman Ji Hwan Bae drew the game's first walk. Suddenly Gray — staked to a two-run lead on the strength of a pair of two-out RBI hits, one by Kepler in the first inning and another by Michael A. Taylor in the fifth — was in danger of losing his lead.

Gray struck out Bryan Reynolds on three pitches to record a second out. But McCutchen, the 2013 NL MVP and five-time All-Star, grounded a two-strike single up the middle to score Peguero and Delay and tie the score. Ke'Bryan Hayes then dropped a liner in front of left fielder Joey Gallo to drive home the third run and give Pittsburgh the lead.

Keller, who had retired 10 straight Twins earlier in the game, made it stand up, even when Polanco drew a walk to open the Twins' sixth inning, and Carlos Correa and Kepler followed with singles to load the bases. With his own lead at stake, Keller struck out Royce Lewis on four pitches, Solano on three, and after falling behind Gallo 3-1, zipped a 97-mph high-and-away fastball past him for his 12th and final strikeout.

The Twins finished with 15 strikeouts, the franchise-record 12th time they've reached that lofty number.

"He has good stuff. He worked the inner third against our lefties, and it was effective for him," Baldelli said of Keller. "He got some calls, I think, that I don't know if they're strikes, but they're close. He made some good pitches and made our life difficult."

McCutchen seemed to end all drama in the ninth, hitting a 438-foot three-run blast into the upper deck in right-center. Those three runs became critical when the Twins put the first three runners on in the bottom of the ninth, scoring a run. But the rally was quickly squashed as Correa grounded into his major league-leading 24th double play.