The Astros ended their team-record losing streak at 12 games, beating the Pittsburgh Pirates 9-5 Sunday behind three hits and three RBIs from Marwin Gonzalez.
Hours after Houston traded third baseman Chris Johnson to Arizona - the Astros' fifth deal of the month - Jordan Schafer homered and drove in three runs.
Houston, a big league-worst 35-68, won for only the third time in 28 games. Lucas Harrell (8-7) allowed two runs and five hits in 5 2-3 innings, his first victory in five starts since a six-hit shutout against San Diego on June 27.
James McDonald (10-5) walked a career-high seven in five innings, allowing five runs and six hits. He has lost consecutive decisions for the first time this season and has an 8.71 ERA in his last four starts.