The nine runs, Houston's most since plating the same number on June 18 against Kansas City, strongly supported starter Lucas Harrell, who gave up two runs in 5 2/3 innings and earned his eighth victory.
Harrell wasn't happy with how he pitched, saying his arm didn't feel in sync with the rest of his body. He walked three to go along with five strikeouts.
"The offense carried us today," Harrell said. "Everybody swung the bat well."
An accurate statement -- seven different Astros crossed the plate. The hitters with the most influence in the victory came from all parts of the roster.
Relegated to pinch-hitting and pinch-running duties in the last four games, Jordan Schafer picked up three RBIs, two coming on his fourth homer of the season in the fourth off starter James McDonald.
Scott Moore, who started at third base after the Astros traded regular third baseman Chris Johnson to the D-backs before Sunday's game, had a pair of RBI singles.
Regular J.D. Martinez knocked in his team-leading 53rd run, helping the Astros score more than five runs for the first time since July 20 at Arizona.
Gonzalez, who will be the Astros' lone natural shortstop after Brian Bixler was sent to Triple-A Oklahoma City following the game, went 3-for-5 with a three-run double in the eighth to cement the Astros' first victory in nearly two weeks. Gonzalez didn't have a hit in his last three starts.
"It was awesome. Every hit today, I felt good because I was like 0-for-15 the last three or four games," Gonzalez said. "It was hard to get a hit. While I was positive the whole time, I was hitting the ball good, but it was hard to get a hit."
Manager Brad Mills was pleased with the aggressive baserunning in the face of a grinding losing streak.
"I loved how our guys continued to battle, even through this thing," Mills said. "Those losses were tough losses."
All in all, it was a much-needed -- and hard-earned -- win for a team that had lost its last five games by no more than two runs.
Harrell threw 108 pitches, 69 for strikes. The right-hander breezed through the first three innings, only allowing a single from Pedro Alvarez in the second. In the fourth, he walked Neil Walker and gave up a towering two-run homer to Jones, his 16th of the year. The Pirates took a 2-1 lead.
Schafer's two-run homer in the fourth, his first since June 23, gave the Astros a 3-2 lead. Behind a triple, a single and a double to start the fifth, the Astros plated two and took a 5-2 advantage into the sixth.
Harrell, who leads the National League in innings by a rookie, left the game with the bases loaded after 5 2/3 innings. Reliever Fernando Rodriguez, who told Mills he was OK to pitch on Sunday after throwing on Friday and Saturday, retired Most Valuable Player candidate and pinch-hitter Andrew McCutchen to end the sixth.
Trailing, 9-3, entering the ninth, the Pirates scored a pair of runs off Chuckie Fick before Xavier Cedeno and Wilton Lopez combined to record the game's final three outs.
The Astros are now 25-27 at Minute Maid Park after a 1-6 homestand.
"When we have played so well all year long at home, to go through a rough homestand like this, that's a big breath of fresh air to be able to [win] and to take it out on the road with us," Mills said.
Amid a massive roster upheaval, Mills isn't worried about his team getting down.
"These guys know if they go out and play, they're putting themselves in a position to be with this ballclub and organization in years to come," Mills said. "This is a good time for them to really come out and play and not be focused on other things, but be focused on what they need to do."