HOUSTON -- Freddy Sanchez was tagged out going for an inside-the-park home run last season. He refused to let that happen again.
Jason Bay and Adam LaRoche also homered in the inning off Houston closer Jose Valverde, who came in with the Astros leading 3-2.
Sanchez's shot off Tim Byrdak was Pittsburgh's first inside-the-park home run since Chris Duffy hit one against the New York Yankees on June 8, 2007. It was the second inside-the-park homer against Houston at home this season -- Chicago Cubs' catcher Geovany Soto had one on May 19.
"I was just running as hard as I could," said Sanchez, who went 3-for-6. "I gave it all I had. I got fortunate, I guess."
As he rounded third, Sanchez had a flashback to a game against the Cubs last season, when he was out at the plate on an inside-the-park try.
"That was kind of going through my head," he said.
Sanchez came into the game hitting .230 and was only 9-for-44 in July. He's hoping a game like this will kick-start his season.
"I can't look at what I did the first half," he said. "I can only look at this half and that's it. I'm just thinking at-bat to at-bat, not even day by day and doing whatever I can to help these guys."
Valverde (4-3) had converted 23 of his last 25 save opportunities before Bay hit the tying solo homer off the facade in left-center, his 20th of the season.
Xavier Nady singled before LaRoche homered into the porch in left field. Jason Michaels walked and Jack Wilson added an RBI single later in the inning before Houston manager Cecil Cooper brought in Byrdak to relieve Valverde.
"He was giving a little too much of the plate," Cooper said of his closer. "Sometimes, that happens. He just did not have real good control."
One out later, Sanchez drove a 1-0 pitch to right-center and the ball took a sideways bounce off the padding at the bottom of the fence, skipping away from right fielder Hunter Pence.
Once Pence got the ball back to the infield, Sanchez was already heading for home he slid ahead of the late relay throw to Houston catcher Brad Ausmus.
Sanchez let out a deep breath when he realized he'd made it.
"When I was sliding headfirst and I saw the ball go past," he said, "I just stayed there for a little bit."
Tyler Yates (4-2) pitched a scoreless eighth for Pittsburgh and Denny Bautista shut out the Astros in the ninth.
After getting outscored 28-9 in a four-game sweep by Colorado, the Pirates were relieved to rediscover their offense in Houston.
"It was looking at one point like the same old story from the last four days," Bay said. "Hopefully, we're over that and can get back on the right side of the ship."
Carlos Lee drove in two runs and Ausmus added an RBI double for the Astros, who stranded 13 runners and fell to 2-5 against Pittsburgh this season.
"We had a lot of opportunities," said Ty Wigginton, who went 0-for-2 with a walk. "I had a couple of situations myself. I should've moved the runner over and I just didn't get it done."
Lee broke a 2-all tie in the fifth with an RBI double off the left-field scoreboard. Cooper replaced starter Runelvys Hernandez with Geoff Geary in the sixth inning. Hernandez allowed eight hits and struck out three.
Geary pitched 1 2/3 innings of scoreless relief and hasn't allowed a run this month, a span of 13 2/3 innings.
Doug Brocail, who gave up three runs while getting just two outs in a 4-3 loss at Pittsburgh on July 8, gave up two singles in the eighth.
The Astros scored their runs off Pittsburgh starter John Van Benschoten, who was recalled from the minors on Monday. Sean Burnett relieved Van Benschoten for the sixth. Home plate umpire Fieldin Culbreth was hit by a pitch on his left forearm. Astros assistant athletic trainer Rex Jones ran out to check on him, but Culbreth stayed in the game.