The Pirates improved to 48-30 - they are 18 games over .500 for the first time since 1992, their last winning season.
Neil Walker hit a two-run homer off Felix Hernandez to put Pittsburgh ahead in the fourth. Seattle tied it in the sixth on Raul Ibanez's team-leading 18th home run.
It was 2-all when Pedro Alvarez singled to lead off the ninth inning against reliever Charlie Furbush (1-4) and advanced on a sacrifice bunt from Neil Walker.
After a groundout by Gaby Sanchez, Travis Snider was intentionally walked. Mercer followed with an RBI single off Yoervis Medina, and the Pirates added an insurance run when a wild pitch on a third strike from Medina allowed Snider to score and Starling Marte to reach first base.
Mark Melancon earned his second save of the season. Mike Zunino delivered a pinch-hit single and Nick Franklin singled to put a pair of runners on with two outs in the ninth, but Kyle Seager grounded out.
Vin Mazzaro (4-2) picked up the victory with two innings of scoreless relief.
Hernandez bounced back to form after his worst start of the season. He blew a seven-run lead against the Los Angeles Angels in his last appearance, but struck out 11 against the Pirates. Hernandez gave up six hits and walked two.
The Mariners squandered a chance to take the lead in the eighth. With the game even, Kendrys Morales doubled and the Pirates intentionally walked Ibanez to put a pair of runners on with one out. Mazzaro managed to escaped by striking out Justin Smoak and getting Michael Saunders to fly out.
Walker hit his sixth home run, connecting with two outs.
Seattle managed to get a run back in the bottom half without a hit. Ibanez reached first after swinging at a third strike wild pitch that got away from catcher Russell Martin, then Smoak hit a grounder and Mercer mishandled the throw to second, the ball deflecting off the shortstop's glove.
Ibanez took advantage of the Pirates' defensive shift and advanced to a vacated third base on the misplay. A sacrifice fly from Saunders made it 2-1.
Jeanmar Gomez turned in a fine outing for the Pirates in his first start off the disabled list. He allowed just three hits and an unearned run in five innings with five strikeouts.
Ibanez tagged Justin Wilson for his ninth home run in June.
NOTES: Notes: The Pirates optioned RHP Duke Welker to Triple-A Indianapolis in order to activate Gomez from the 15-day disabled list. ... Ibanez has just 12 hits against left-handed pitchers this season but six of the hits have been home runs. He is batting .214 with six home runs and 12 RBIs against lefties.