Zack Littell sat in the bullpen and watched everything unfold on Tuesday. He saw the innings pile up, the clock strike midnight and the door to bullpen open and close over and over until he was the last man to go through it.

"It kept shrinking and shrinking and then it's just me," Littell said. "I was like, 'It's kind of boring out here. Nobody's here to talk to, just hanging out.' "

The Twins were clawing through one of the longest games in club history. And someone was going to be really ticked off at the end. Because if you play that long, you better win.

"To lose a game like that would take way more out of you than winning a game propels you," catcher Mitch Garver said. "That would be so hard to go that far and use all the pitchers that you did, grind out at bats and then lose. It feels great to be on top. I've been on the losing side of those before."

Despite a series of self-inflicted setbacks — such as baserunning mistakes, botched scoring opportunities and even a collision in the outfield that allowed a ball to drop in for a double — there were smiles in the Twins clubhouse early Wednesday morning.

Max Kepler, who tied the score in the eighth inning with an RBI single, then again with a home run in the 13th, ended the game with a 17th-inning, bases-loaded single through a five-man infield as the Twins edged Boston 4-3.

The Twins bullpen, which has had its share of mishaps in recent weeks, limited a Red Sox offense that was fifth in baseball in runs scored to only two runs over 11 innings. Boston was 1-for-13 with runners in scoring position as Twins pitchers left a least one Red Sox runner on base in each of the final six innings.

"Guys are coming out there throwing an inning, two innings, like it's nothing," Twins manager Rocco Baldelli said of a relief corps that included Ryne Harper, Trevor May, Taylor Rogers, Tyler Duffey, Blake Parker, Mike Morin, Matt Magill and Littell. "Guys are flashing stuff that we maybe haven't even seen before. It feels like there was a lot of adrenaline. Everyone was up for it."

Eddie Rosario had four hits, including three doubles, the last one helping set up the winning run. Kepler, who replaced a banged-up Marwin Gonzalez in the sixth inning, finished 3-for-5 with three RBI. Littell pitched the final two innings to pick up his first major league victory.

There were missteps along the way — a game that long typically can't happen without them — but the Twins used a collaborative effort to pull off their first walkoff victory of the season. And, for the sixth time this season, they avoided a three-game losing streak.

"That was one of the best games I've been a part of, ever, in baseball," Baldelli said. "I think a lot of people in that clubhouse can say the same thing."

It ended the longest game, by innings, in Target Field history. Timewise, the 5-hour, 45-minute game ties for the fourth longest in Twins history, matching a 13-12 loss from May 17, 2002, at Yankee Stadium — Jason Giambi hit a walkoff grand slam in that one.

The winning rally took place with Boston lefthander Brian Johnson on the mound. He was a late replacement for righthander Hector Velazquez, who was warming up for his fifth inning of relief but appeared to hurt his back and had to leave the game.

Luis Arraez, who was called up on Tuesday to replace the injured Ehire Adrianza and pinch ran for Nelson Cruz in the 12th inning, delivered a one-out single to center. Rosario followed with a double to right, and Arraez was held at third by coach Tony Diaz. C.J. Cron was intentionally walked to load the bases.

The Red Sox went to a five-man infield, but Kepler hit Johnson's second pitch — the 448th of the night/morning — past Michael Chavis at first. And the painstakingly long game was over.

"I'm glad I could just help support the team win, bring some energy to a longer-than-expected game," Kepler said. "I can't imagine how the guys who started feel but I'm pretty worn out, and I didn't even play the whole game."

The Twins were basking in the afterglow of a rare night in front of an announced crowd of 25,741 at Target Field. Later Wednesday, they will assess their bullpen and figure out if adjustments are needed. They will check on Gonzalez, who hobbled off the field before Kepler pinch hit for him.

But they will savor a night/morning that started out like any other game but went into extra innings then became surreal.

"Do you know how many pitches I called tonight?" said Garver, who was picked off third base with nobody out in the sixth, then committed a throwing error in the 17th that enabled Boston to put a runner on third with nobody out. Neither mistake ultimately cost the Twins.

Garver added: "How many times the same dude steps up to the plate and I'm like, 'Uh, I think we threw him this first pitch. I think he did this...' you just start blacking out. It's crazy."