HOUSTON (AP) -- One night after staging an impressive comeback victory, the Minnesota Twins found themselves on the other side of an impressive rally.
They managed to stick around long enough to get the win.
Clete Thomas scored the go-ahead run on a wild pitch in the 12th inning and Darin Mastroianni added a two-run double, helping the Twins beat the Houston Astros 9-6 on Tuesday for their third straight win.
''A long one but a good one for us,'' Minnesota manager Ron Gardenhire said.
Thomas reached on a fielder's choice and went to third on Josmil Pinto's double. Kevin Chapman (0-1) then uncorked a wild pitch with pinch-hitter Ryan Doumit at the plate.
Mastroianni provided a couple of insurance runs when he doubled with two down as Minnesota recovered after Glen Perkins blew a save opportunity in the ninth.
''We haven't lost a lead too many times with Perk in the game; he just didn't have his stuff,'' Gardenhire said. ''He said it - he couldn't locate the baseball.''
Brian Dozier and Trevor Plouffe homered for Minnesota, which improved to 5-0 against major league-worst Houston. Plouffe and Pinto had four hits apiece, and Mastroianni went 3 for 6 with three RBIs.
''Chapman threw me a slider, and I thought it was a ball but the umpire called it a strike,'' Pinto said of his key double in the 12th. ''I told myself to try a little harder and the next pitch was a slider and I hit it.''
Brandon Barnes had three hits and five RBIs for the Astros, including a tying three-run homer off Perkins with two out in the ninth.
''(Minnesota) ended up doing a little bit more than we did,'' Astros manager Bo Porter said.
Caleb Thielbar (3-2) pitched two hitless innings for the win and Josh Roenicke finished for his first save.
Barnes and Marwin Gonzalez walked with one out in the 12th, but Roenicke retired the next two batters to get out of the jam.
The Twins won 10-6 in Monday's series opener by scoring five times in the last two innings, including Chris Colabello's tiebreaking grand slam in the ninth. But Houston responded with its own comeback in the second game.
With two out and none on in the ninth, Perkins hit Brett Wallace with a pitch and L.J. Hoes then singled to right to put runners on the corners. Perkins got ahead of Barnes 0-2 before he sent the next pitch over the wall in right for his seventh homer.
''We've been fighting,'' Barnes said. ''We've been on the wrong side of some games, but we fight. We battle. We're young and we're still learning.''
The Twins got to Jarred Cosart for two in the first and two more in the third while building a 4-1 lead. Dozier went deep in the first and Plouffe added another two-run shot in the third after Cosart walked Josh Willingham on four pitches with two out.
Cosart, who entered with a 1.59 ERA through eight starts, gave up four runs and five hits in four innings. He struck out five and walked three.
''It's kind of what everyone's been waiting for,'' Cosart said of his outing. ''I didn't get the results. A starter's job is to keep the team in the game and give us a chance to win the game. I didn't do that today.''
Chris Carter hit his 27th homer in the second for the Astros, and Barnes' two-run single cut Minnesota's lead to 4-3 in the seventh. But Houston lost a chance for a bigger inning when Barnes was thrown out at the plate when Gonzalez was caught between first and second.
Pedro Hernandez allowed two runs and six hits in six-plus innings for the Twins. It was his first start since being recalled from Triple-A Rochester on Aug. 30 after Samuel Deduno went on the 15-day disabled list with a right shoulder injury.
''We used a lot of pitching,'' Gardenhire said. ''Our starter was good; Hernandez was fine. We had like a 70- to 80-pitch limit on him and he was pretty close to right around there.''
NOTES: Astros All-Star C Jason Castro was out of the lineup after spraining his right knee on Monday. ''The good news is that there's no structural damage,'' Porter said. ''He's day to day and he's obviously sore right now.'' Castro said he had a cyst drained Tuesday. ... Astros 3B Matt Dominguez was out of the lineup with a stomach illness. ... The Astros acquired C Matt Pagnozzi from Atlanta for cash. Houston transferred RHP Edgar Gonzalez to the 60-day disabled list to make room for Pagnozzi on the roster.