A bounce here, a ricochet there, an inch either way. The smallest margins made the biggest differences, and ultimately they delivered — then denied — the Twins a victory over Detroit that could have pulled the Twins within, yes, the tiniest possible margin away from a playoff spot.

Ian Kinsler singled home the tie-breaking run in the 12th inning, and J.D. Martinez blasted a two-run homer off Brian Duensing as punctuation, an acrid ending to what had been a thrilling night that featured ninth-inning rallies by both teams. It goes down as a 7-4 Tigers victory, but this one felt like more than one ordinary loss.

"It's disappointing, but you're going to have those kind of losses," Twins manager Paul Molitor said. "They're kind of magnified with where we're at. … But we're still in a relatively competitive position."

Yes, but Twins fans had probably erased a game off the Astros' lead already. Houston and its ace lefthander, Dallas Keuchel, suffered a 14-3 loss to Texas in Arlington, offering Minnesota the opportunity to move within one-half game of the Astros for the second AL wild-card berth. And if one of about 10 bounces had gone a different way, the game could have, too.

Instead, last-place Detroit departs with two wins in the three-game series, having clinched the season series 10-6 with three games to play at Comerica Park. The Twins, after failing to cash in on Houston's loss, remain 1 1/2 games out of a wild-card spot with the Angels, two games behind the Twins, arriving Friday for a critical four-game series.

Trevor Plouffe laced a double about 18 inches inside the third-base bag to tie the game in the bottom of the ninth, but on a play that could have ended it, Shane Robinson's fingertips touched home plate a split-second after he was tagged out, and the game eventually went to extra innings.

But those were hardly the only by-an-eyelash moments in this one. The Tigers' first runs scored on a ball that landed an inch or two inside the foul line. A Twins' go-ahead rally was aided by a ball that bounced directly over third base, and a line drive that ticked off the webbing of a fielder's glove. Detroit answered in the ninth when Brian Dozier, after turning a pair of diving stops into double plays already, missed by the width of a baseball knocking down the Tiger's go-ahead grounder.

That last one spoiled Kevin Jepsen's perfection. But perfection never lasts in baseball.Jepsen, 7-for-7 in save opportunities since becoming a Twin last month, had never, in 17 appearances over his eight-year career, allowed an earned run to the Detroit Tigers. Both streaks came to an end in the ninth, on a rally that began when Jepsen grabbed Victor Martinez's well-placed dribbler just to the left of the mound, and bounced the throw in the dirt and off Joe Mauer's chest. After a single by Tyler Collins put the go-ahead run in scoring position, rookie Jefry Marte ground a single just out of Dozier's reach and into center field, scoring two Tigers and appearing to hand the Twins an excruciating loss.

"The first baserunner, it's just unfortunate he hit it where he did and we couldn't make the play. … [Jepsen] probably had more time than he thought he did," Molitor said. "Collins, he proved in the first inning he could hit a fastball and he got one he could handle and rifled it to right field. And [then] they got the base hit up the middle on a first-pitch breaking ball."

But the Twins bounced back, tying the game just two batters later against Detroit's Bruce Rondon, with Miguel Sano drawing a walk and Plouffe doubling home pinch-runner Eduardo Nunez. That inning didn't end with the Twins' seventh walk-off win, though, because Robinson, trying to score on a grounder to short, was tagged out just short of the plate.

That ninth inning was the Twins' second clutch rally of the night. In the seventh, Torii Hunter lined an RBI hit off third baseman Marte's glove, and Eddie Rosario singled home Sano to give the Twins a temporary 3-2 lead.

Rosario had already had a memorable night, before the go-ahead RBI. His third-inning home run off fellow rookie Daniel Norris was Rosario's 10th on the season, and gave him double-digits in singles, doubles, triples and home runs, making him the 10th Twin ever to have such a varied offensive season, and the first since Cristian Guzman in 2001.

Joe Mauer reached a milestone in the middle of a rally, too. In the seventh inning, Mauer walked, reaching first base for the 36th consecutive game, tying his own career high and leaving him just six games behind Bob Allison's 54-year-old franchise record.

Ervin Santana pitched seven innings, and came within about three inches from shutting out the Tigers. With two on base in the first inning, Tyler Collins lifted a fly ball to right field that bounced just inside the chalk, a two-run double to give Detroit the early lead. But Santana, with plenty of help from the Twins' defense, never allowed another Tiger to reach second base, allowing just four hits.