Trailing 1-0 since the first inning, the Pirates got the equalizer with two outs in the seventh when Alvarez lined a 2-0 pitch from Daniel Hudson (1-1) over the right field fence.
Pittsburgh grabbed the lead in the next frame. Clint Barmes and Andrew McCutchen each singled with two outs, chasing Hudson and bringing on David Hernandez. Neil Walker then blooped a hit to center, scoring Barmes.
Juan Cruz made the lead hold up with a 1-2-3 ninth for his second save in two days and the Pirates completed a nine-game road trip with three wins in four contests.
Brad Lincoln (1-0) earned the victory with three scoreless innings in relief of James McDonald.
Hudson finished by allowing two runs on six hits over 7 2/3 frames, walking three and striking out five.
Jason Kubel got the only RBI for the Diamondbacks.