Brandon McCarthy won consecutive starts for the first time in more than a year, and the Diamondbacks' offense exploded for seven runs in the ninth inning in a sweep-averting win over the Pittsburgh Pirates on Thursday night at PNC Park.

Rookie David Peralta had three hits, including a two-run homer, and Paul Goldschmidt had a double, a triple and a walk for the Diamondbacks, who scored as many runs on Thursday as they had in their previous six games combined.

Grinding it out: McCarthy said he didn't feel particularly sharp and called it "a little bit of a fight" to get through 52/3 innings, but he allowed just two runs to pick up his third victory of the season.

"I felt like I managed to keep pace well, and even when things got a little dicey I kept trying to make pitches and let things work out," he said.