HOUSTON -- Astros shortstop Marwin Gonzalez didn't have much time to think about the way Rangers starter Yu Darvish had retired teammates Jason Castro and Carlos Corporan on three pitches to start the ninth inning Tuesday night to get within an out of a perfect game, but he had one thought as he stepped toward the plate.

"I didn't want to be the last out," Gonzalez said. "I was trying to look for a good pitch to hit and put the ball in play. That's all I was thinking in my mind."

Gonzalez came through, stroking the first pitch he saw -- a fastball on the outside corner -- up the middle and into the outfield to end Darvish's bid for a perfect game. The hit provided a huge sigh of relief for the Astros, who were on the wrong end of Matt Cain's perfect game last June.

"Marwin did a great job, got a good pitch to hit, base hit back up the middle to break up the perfect game and the no-hitter," Astros manager Bo Porter said.

Gonzalez, a career .234 hitter in only 205 big league at-bats entering the season, struck out swinging and grounded out to first base in his first two-bats against Darvish. He was in the lineup last year when Cain threw baseball's 22nd perfect game against the Astros and knows how demoralizing it can be.

"We didn't want to lose like that, and I'm grateful I got the hit and he didn't get a perfect game," Gonzalez said.

Darvish was rolling entering the ninth, having thrown 107 pitches before Castro, who made the final out in Cain's no-hitter, grounded out to shortstop on the second pitch of the inning. Corporan rolled over the next pitch and hit a routine grounder to second. Darvish was one out from history.

"The first two batters, J.C. and Corporan, he threw a fastball away the first pitch to them, and I realized he was going to throw it to me, too, and I was waiting on the pitch," Gonzalez said.

Gonzalez, 24, is a switch-hitter from Venezuela known more his slick defense than his offense, and he made one of the best plays you'll see in the first inning by going deep into the hole and throwing out Adrian Beltre.

The Astros took Gonzalez in the Rule 5 Draft in 2011 and kept him on their roster all last year. He started on Opening Day in 2012 because Jed Lowrie was on the disabled list and wound up making 38 starts at shortstop before beating out Tyler Greene this spring (the Astros cut Greene and signed Ronny Cedeno to split time at the position).

But it wasn't his defense that saved the day for Houston on this night.

"I think the guys were pretty relieved," Porter said. "No one wants to be part of history in that way. You would rather be on the other side of it and be the team that's throwing the no-hitter or the perfect game, but again, our caps go off to [Darvish]. He was tremendous tonight, and I'm pretty sure we'll see him again down the road."