Dillon Gee pitched another gem against the Pirates, and John Buck hit a two-run single to lead the New York Mets to a 4-2 victory Sunday and avoid a sweep by Pittsburgh before the All-Star break.

Gee (7-7) allowed just one unearned run in 6 2/3 innings to the Pirates (56-37), who entered the day tied with St. Louis for the best record in the major leagues and the National League Central lead.

Gee is 3-0 with a 1.38 ERA in five career starts against Pittsburgh. He scattered, five hits, struck out two and walked one.

Buck's hit capped a three-run first inning against fill-in starter Gerrit Cole (4-3), who lost his third straight start after becoming the first Pirates pitcher since Nick Maddox in 1907 to win the first four of his career.

Buck, Eric Young Jr. and Marlon Byrd each had three hits for New York, which finished a 6-3 road trip. The Mets will host the All-Star Game on Tuesday night at Citi Field.

Bobby Parnell earned his 17th save in 20 opportunities with a scoreless ninth despite giving up back-to-back singles to Clint Barmes and pinch-hitter Russell Martin with one out. He got Jordy Mercer to fly out to end the game.

Starling Marte had two hits for the Pirates, whose three-game winning streak was snapped.

Cole surrendered three runs and six hits in five innings with two walks and five strikeouts. He started in place of All-Star left-hander Jeff Locke, who was scratched from this start on Saturday because of lower back tightness.

The Mets took a 3-0 lead in the first inning. Byrd bounced a run-scoring, ground-rule double into the left-field seats, and Buck lined a two-run single to right.

Marte also bounced an RBI double into the seats in the third inning to draw the Pirates within 3-1.

Daniel Murphy tripled in a run in the seventh to restore the Mets' three-run lead.

Pittsburgh put runners on second and third with none out in the eighth on a single by Mercer and a double by Andrew McCutchen, but the Pirates scored only one run when Jose Tabata grounded out against LaTroy Hawkins.

NOTES: Mets manager Terry Collins said the blister on RHP Matt Harvey's right index finger has healed and he will be able to pitch in the All-Star game. Harvey is a prime contender to be the NL's starting pitcher on Tuesday despite being scratched from his scheduled start Saturday against the Pirates because of the blister and to limit his innings this season. . Mets 1B Ike Davis got the day off after going 0-for-8 in the first two games of the series. Josh Satin started in his place. . Pittsburgh RHP Mark Melancon was added as injury replacement to the NL All-Star roster. That gives the Pirates a five-man All-Star contingent, their largest since 1972. Melancon joins Locke, RHP Jason Grilli, 3B Pedro Alvarez and McCutchen. . Locke said he expects to make his next start July 21 at Cincinnati.