Mercer doubled in two runs to cap a four-run second inning off Zack Greinke and hit his fourth homer of the season in the fourth for the Pirates, who have lost eight straight series and 18 of their last 25 games.
Arizona right fielder Jon Jay hit a two-out, two-run single in the ninth inning before left-hander Felipe Vazquez struck out Jake Lamb with the bases loaded for his 12th save in 16 chances. Jay had two hits.
Taillon (4-5) gave up six hits and two runs, with four strikeouts and two walks while dropping his ERA to 3.94, the lowest it has been since the third week of April.
The Diamondbacks' only runs off Taillon came when left fielder Austin Meadows misplayed David Peralta's deep fly ball into a two-run homer with two outs in the first inning. Meadows glided back to the warning track and reached up to make the catch, but the ball bounced off of his glove and into the front row of the seats.
Josh Bell doubled in a run and Josh Harrison had an RBI for the Pirates.
Paul Goldschmidt singled to extend his hitting streak to nine games.
Zack Greinke (5-5) gave up five hits and five runs in 4 2/3 innings, his shortest appearance of the season, with seven strikeouts and a season-high four walks. He lost for only the second time in 26 home starts. He was 3-0 in seven starts at home this season after going 13-1 in 18 home starts in 2017.
Peralta's homer, his 12th, drove in Jay, who had opened the first inning with an infield single.
The first five Pirates reached base off Greinke in the second inning, when they scored four runs for a 4-2 lead. Colin Moran singled and Francisco Cervelli walked before Bell hit an opposite-field double down the left field line to drive in Moran.
Gregory Polanco walked to load the bases and Mercer drove in two with a double before Polanco scored on a one-out groundout.
--Field Level Media