The first-time All-Star was a one-game hero.

Jason Castro’s 427-foot, three-run home run to deep right-center field in the seventh inning Saturday was a game-changer for the Astros, who powered past the Rangers 9-5 during an American League West matchup at Rangers Ballpark.

Rookies Brandon Barnes and Jake Elmore hit two-run homers and the struggling Astros (32-56) beat the Rangers (50-37) for the first time since a March 31 season-opener.

Less than four hours after being named to the 2013 MLB All-Star game as an American League reserve, Castro again proved why he’s been the Astros’ best overall player this season. He threw out two runners, improved his average to .271 by going 2-for-5 and flipped a game that had been tied by the Rangers’ four-run sixth inning.

“I’m at a pretty comfortable place just in my approach and my mechanics,” Castro said. “Everything’s coming together and I’ve been happy with some of the work that I’ve put in to get me where I’m at.”

Rangers starter Yu Darvish came one out away from throwing a perfect game against the Astros on April 2. The Astros recorded three runs against the righty May 11, though, and Barnes made it 2-0 Astros on Saturday when he hammered a 1-2 fastball into left-center field for a two-run homer.

Darvish was consistently hittable during the initial four innings. Marc Krauss, Jimmy Paredes and Castro collected singles, Brett Wallace doubled down the right-field line, and Darvish hit 98 pitches before the sixth inning arrived.