HOUSTON -- HOUSTON -- 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 Minnesota Twins beat the Houston Astros 9-6 on Tuesday night.

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.

Brian Dozier and Trevor Plouffe homered for Minnesota, which has won three in a row. Plouffe had four hits and Mastroianni went 3 for 6 with three RBIs.

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.

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.

One night after staging an impressive comeback, capped by a ninth-inning grand slam by Chris Colabello in a 10-6 win, the Twins found themselves on the other side of an impressive rally.

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.

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 pitched 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.

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.

Copyright 2013 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.

More From KSOO-AM / ESPN Sioux Falls