It marked the ninth time this season New York lost a game in which it led in the eighth inning or later. The Mets have struggled lately minus injured All-Star closer Billy Wagner.
Aaron Heilman (2-7) began the ninth with a 5-4 lead, but allowed four straight Pirates to reach in the ninth after striking out leadoff hitter Nate McLouth.
Ryan Doumit atoned for an earlier error with a tying single off the wall in right-center and Heilman hit Andy LaRoche with a pitch to load the bases.
Scott Schoeneweis relieved and got Brandon Moss to ground into a forceout at the plate. Pearce followed with a his tiebreaking single to center.
Carlos Beltran hit a leadoff single in the bottom half after frustrated Mets manager Jerry Manuel was thrown out by umpire Bill Hohn for arguing balls and strikes. But John Grabow struck out Carlos Delgado and got Fernando Tatis to ground into a double play.
Denny Bautista (4-1) worked a scoreless eighth for the win and Grabow earned his second save. Heilman absorbed his third blown save in five opportunities.
New York wasted an effective start by Martinez, who allowed one run and three hits. David Wright hit a three-run home run and Robinson Cancel had his first career homer.
Doug Mientkiewicz had three hits and drove in two runs for Pittsburgh, which held second baseman Freddy Sanchez and shortstop Jack Wilson out of the starting lineup because of minor shoulder problems.
Sanchez had a pinch-hit RBI double as the Pirates pushed across three runs in the seventh to cut it to 5-4.
Zach Duke (4-11) allowed eight hits and five runs in six innings for the Pirates. He was headed for his sixth consecutive loss before Pittsburgh rallied.
The Mets got off to a fast start against the left-hander, who was coming off one of his best starts of the season. Jose Reyes led off the first with an infield single, Nick Evans reached on third baseman LaRoche's error and Wright hit his 23rd home run.
The Pirates' defense hurt them again in the third. Cancel hit a two-out single to center and McLouth made a nice throw to the plate but Doumit dropped it, allowing Delgado to score.
Cancel, getting the start behind the plate with Ramon Castro ailing, hit a drive off the screen next to the left-field foul pole in the sixth.
The Pirates and Mets started late when the game, a makeup of an April 28 rainout, was delayed 31 minutes because of rain in the area of Shea Stadium. The first few innings were played under overcast skies that eventually gave way to a sunny afternoon.
Notes: Pirates RHP Jeff Karstens is scheduled to start Tuesday night against Cincinnati in his first home game since he was acquired from the New York Yankees on July 26. The visit to Shea Stadium was his first trip to New York since the deal. "I just want to take it one start at a time for now, and finish the year strong," said Karstens, who tossed 15 scoreless innings and went 2-0 in his first two starts with Pittsburgh. ... Manuel doesn't think Castro (sore right ankle) will need a stint on the DL. ... Mets 2B Luis Castillo (strained left hip flexor) left a rehab stint with Class A St. Lucie to take care of a personal situation.