Pinch-hitter Hector Sanchez connected on the go-ahead RBI single in the ninth inning and the San Francisco Giants rallied for a 3-2 win over the Houston Astros on Tuesday night.

The Giants were down 2-1 entering the ninth. Brandon Belt singled off Wesley Wright to start inning before pinch-hitter Joaquin Arias doubled down the left field line off Wilton Lopez (5-3) to score Belt and tie it 2-2.

Sanchez completed the rally with his one-out line drive to center field that scored Arias.

Houston took the lead on a wild pitch by Matt Cain in the eighth inning. The game was tied 1-all when Jimmy Paredes, in his first game since being recalled from Triple-A Oklahoma City, drew a walk. Brett Wallace singled before a sacrifice bunt by Jason Castro left runners at second and third.

Then came the wild pitch in the dirt that bounced in between the legs of catcher Buster Posey and off the backstop. Posey went to get the ball and Paredes trotted home ahead of the throw and over a diving Cain to put Houston up 2-1 and chase Cain.

Santiago Casilla (5-5) retired the last two batters in the eighth for the win and Sergio Romo threw a perfect ninth for his seventh save.

Angel Pagan put San Francisco up 1-0 when he connected on a home run to right field with two outs in the fifth inning. Houston evened things up when Fernando Martinez opened the bottom half of the inning with a homer to right-center.

The loss drops new Houston manager Tony DeFrancesco to 1-7 and came in front of 13,516 — the smallest crowd in the history of the 12-year-old ballpark. DeFrancesco took over on Aug. 19 after Brad Mills became the first manager fired in the majors this season.

Houston starter Bud Norris was lifted in the seventh inning with a blister on his right middle finger. He retired the first two batters in the inning before falling behind 2-0 to Pagan.

Trainers checked him out and chatted with him before he was replaced by Fernando Rodriguez.

Norris is mired in a career-worst 10-game losing streak and hasn't won since May 21. He allowed six hits and a run with seven strikeouts.

Cain, who pitched a perfect game against Houston on June 13, allowed six hits and two runs with three walks in 7 1-3 innings.

Cain didn't allow a hit until Wallace doubled with one out in the fourth inning. Pagan fielded it near the wall in center field and threw to cutoff man Brandon Crawford, who caught the throw right before Gregor Blanco came dashing in from left field and crashed into him.

The collision sent both players tumbling to the ground, but neither player was injured.

Cain was helped by his defense in the first inning when Castro hit a pop fly into foul territory. Pablo Sandoval attempted to make the catch, but the ball bounced out of his glove and into the air. Crawford then made a diving play to grab it before it hit the ground for the out.

NOTES: Giants reliever Guillermo Mota was activated from the restricted list on Tuesday after serving a 100-game suspension for his second positive drug test. LHP Jeremy Affeldt has been placed on the paternity list to make room on the roster for Mota. ... The teams continue the series on Wednesday when San Francisco left-hander Barry Zito opposes Dallas Keuchel.