PITTSBURGH (AP) -- Jordy Mercer knows the routine. He figured it was time he experienced it for himself.
The Pittsburgh Pirates second baseman singled up the middle off Gonzalez Germen with two outs in the 11th inning to send teammate Andrew McCutchen sprinting home with the winning run in a 3-2 victory over the New York Mets on Friday night.
Mercer celebrated the first walkoff hit of his career and the sixth of Pittsburgh's stunning season by flipping his bat in the air and then running for safety.
''You make them chase you down because you know you're going to get punished afterward, punched and stuff,'' Mercer said. ''It's all worth it in the end, though.''
McCutchen led off the 11th with a walk, stole second and then easily beat the throw home from center fielder Juan Lagares to end the Mets' four-game winning streak.
The Pirates stayed one game behind St. Louis in the tight NL Central race.
Vin Mazzaro (5-2) retired all three batters he faced to earn the victory. Starling Marte had two of Pittsburgh's six hits, and Pedro Alvarez added his 24th home run.
Mets All-Star David Wright had two hits and extended his hitting streak to 12 games. He had an RBI single but also flied out with two runners on to end the New York 10th. Kirk Nieuwenhuis hit his third homer of the season for New York.
Germen (0-1) got only two outs in his first inning in the majors and took the loss. He struck out Alvarez and Gaby Sanchez with McCutchen on second before Mercer's grounder slipped by shortstop Omar Quintanilla and into the outfield.
''He made some great pitches, too,'' Mets manager Terry Collins said of Germen. ''The 3-1 pitch to Gaby Sanchez was about as (gutsy) of a pitch that you'll ever see.''
The game carried a little more heat than usual between one team in the midst of a pennant race and another rebuilding.
Wright, the starting NL All-Star third baseman and Home Run Derby captain, added Alvarez to the NL's derby roster on Thursday after Colorado's Carlos Gonzalez pulled out because of a hand injury.
Still, Wright's perceived initial snub of Alvarez wasn't forgotten by Pirates fans. He was booed lustily before each at bat, even though he and Alvarez - who will make his All-Star debut - exchanged a handshake and a brief chat before the national anthem.
''They're knowledgeable fans, they know what's going on and it's cool that they're upset and passionate about it,'' Wright said. ''It made for a nice atmosphere.''
Alvarez wasted little time celebrating. One batter after Jose Tabata reached on an infield single in the bottom of the first, Alvarez hit the first pitch he saw from Jeremy Hefner into the New York bullpen in center field. He trotted past Wright without looking up as the seventh sellout crowd of the season roared.
Alvarez, a New York native, dismissed any sense of payback with his blast. He considers Wright a friend and would rather focus on his breakout season.
''I just try to hit the pitch where it's pitched, and just trying to make good contact and really not worry about trying to put too much on the ball,'' he said. ''You can't really control the home runs. I try my best to make good contact wherever the ball is.''
Hefner settled down and retired 14 straight after Alvarez's homer, needing just 78 pitches to get through seven innings. He allowed three hits and struck out three without issuing a walk.
''Last year and even at the beginning of this year I would have folded or given up more runs or whatever the case may be,'' Hefner said. ''I've been able to bounce back, turn the page and give quality outings after giving up some runs early.''
It marked the eighth straight start in which Hefner gave up two earned runs or fewer, the longest streak by a Mets pitcher since Johan Santana did it over 13 starts between 2008 and 2009.
Pittsburgh's Charlie Morton gave up two runs, six hits, and a walk with four strikeouts in his longest start since returning from elbow surgery last month. Morton rolled through five innings before Wright delivered an RBI single in the sixth.
Morton's only real mistake came on a 2-0 fastball that Nieuwenhuis hit into the first row of seats in right-center to tie it at 2.
NOTES: New York right-hander Carlos Torres (0-1, 0.51 ERA) makes his first major league start in nearly three years on Saturday when he fills in for ace Matt Harvey, who is dealing with a blister on his right index finger and an innings limit. Collins says Torres could earn a regular spot in the rotation. The 30-year-old Torres has allowed just one run in 10 relief appearances since being called up from Triple-A in mid-June. A.J. Burnett (4-6, 3.05 ERA) starts for the Pirates. ... Pittsburgh won't send rookie RHP Gerrit Cole to Triple-A Indianapolis during the All-Star break. Cole is 4-2 with a 3.68 ERA since making his debut on June 11. The right-hander started on Tuesday, and the Pirates will let him have a few days off during the break rather than have him make a spot start in Indianapolis to stay on his routine. ... The Pirates acquired minor league infielder Russ Canzler from Baltimore for RHP Tim Alderson. To make room on the 40-man roster, the Pirates moved RHP James McDonald (shoulder) to the 60-day disabled list.