Hernandez (5-2) allowed a first-inning double to Starling Marte and an RBI single to Andrew McCutchen but blanked the Pirates for the next seven innings to win his fourth consecutive decision.
Hernandez gave up six hits and struck out five before giving way to Tom Wilhelmsen, who pitched the ninth for his ninth save.
Pittsburgh starter A.J. Burnett (3-3) struck out nine and surrendered just two hits but walked four.
He retired the first nine batters he faced but in the fourth he walked Michael Saunders and Jason Bay. After they moved up on a fielder's choice, Burnett threw a wild pitch and Saunders tied the score.
The score remained tied until the seventh when Montero hit his third home run of the season with a drive to center.
Kate Middleton recycles dress at movie premiere
Benedict Cumberbatch's dramatic reading of R. Kelly lyrics is just what you need