Neil Walker collected three hits and drove in three runs, while Josh Harrison finished 3-for-6 with an RBI and a run scored for the Pirates, who have won four of their last five games.
Charlie Morton (2-7) struck out nine and allowed just two runs on three hits with three walks over five frames to pick up the win.
Tim Stauffer (2-2) surrendered two runs on four hits and two walks in just 2 2/3 innings to absorb the loss.
Mercer opened the scoring in the third when he launched a leadoff blast into the second deck in left field.
After Morton fanned, Harrison and Walker stroked back-to-back singles before an Andrew McCutchen walk loaded the bases for Ike Davis, who lifted a sacrifice fly to left to score Harrison for a 2-0 lead.
Pittsburgh tacked on a run in the fourth, as Starling Marte was hit by a pitch to the start the frame and then stole second before scoring on Mercer's single to center.
San Diego finally solved Morton in the fifth, as Alexi Amarista stroked a leadoff single for the Padres' first hit. Cabrera followed with an RBI double before scoring on Smith's base hit to center to bring the Padres within 3-2.
The Pirates got a run back in the sixth on Walker's run-scoring single to right before adding three more runs in the seventh to break the game open.
Harrison made it three straight singles with an RBI base hit to left and Walker followed with a double to right, scoring Mercer and Tabata for a 7-2 spread.
Yonder Alonso's run-scoring groundout in the home half got the Padres within 7-3, but the Pirates scored three more in the eighth on a two-run single from pinch-hitter Gaby Sanchez and an RBI ground-rule double from McCutchen.