Ruben Tejada scored the winning run on a throwing error by catcher Buster Posey and the New York Mets beat the San Francisco Giants 5-4 Saturday after blowing a three-run lead moments earlier in one of the wackiest ninth innings imaginable.

Mike Pelfrey tossed eight terrific innings, outpitching Ryan Vogelsong and helping New York build a 4-1 lead. Emmanuel Burriss hit an RBI single in the ninth, but the Mets appeared headed to a fairly simple victory when Jon Rauch came out of the bullpen with two outs and got pinch-hitter Brandon Belt to hit a high popup to shallow center.

Tejada had trouble with it immediately, though, fighting to get under the ball behind shortstop as it swirled around in the wind. Rookie center fielder Kirk Nieuwenhuis came rushing in and overran the ball, which dropped behind him for a two-run double.

In the dugout, Mets manager Terry Collins jerked his head down and threw his hands on top of his cap. In the stands, fans stood shaking their heads in disbelief.

The botched play brought back painful memories for the Mets, of course. Just a few years ago, second baseman Luis Castillo dropped a similar popup that should have ended a game, allowing the New York Yankees to rally for a comeback victory.

Rauch (2-0) struck out Angel Pagan to keep it tied, however, and Lucas Duda opened the bottom of the ninth with a single off Clay Hensley (1-1). Josh Thole sacrificed and Tejada, who drove in three runs, drew a walk.

Pinch-hitter Justin Turner then hit a grounder to shortstop that could have been an inning-ending double play except that Aubrey Huff, who had just been moved to second base for the first time in his 13-season career, didn't cover the bag.

Burriss hesitated before making a low throw to first and Turner was called safe on a close play. The infield single loaded the bases for Nieuwenhuis, who hit a grounder to Belt at first.

He threw home for the force and Posey tried for a double play, attempting to hit a moving target in reliever Jeremy Affeldt as he raced over to cover first. But the throw sailed wide into right field and Tejada came all the way around from second, sliding in with the winning run.

Pinch-runner Scott Hairston stuck out his leg in front of the plate while sliding home on the forceout and knocked Posey off balance as he threw. Looking for an interference call, Posey argued with plate umpire Doug Eddings to no avail.

Collins pulled closer Frank Francisco in the ninth after San Francisco cut it to 4-2. Tim Byrdak struck out pinch-hitter Hector Sanchez with two on before Rauch came in looking for his first save with New York.

Vogelsong matched a career high with eight strikeouts. He went seven innings, yielding three runs and five hits.

San Francisco had won three straight and six of eight.

Vogelsong had thrown 95 pitches when manager Bruce Bochy let him hit with a runner on second and two outs in the seventh. The pitcher struck out, keeping the score tied at 1.

Tejada's two-run double in the bottom half put New York ahead 3-1. Before that, the Mets were 0 for 7 with four strikeouts with runners in scoring position after going 1 for 10 in those situations during a 10-inning loss Friday night.

New York added an unearned run in the eighth on an infield single by slumping Ike Davis. Huff committed an error at first base earlier in the inning.

Belt took over at first after his pinch-hit double and Huff had to shift over to second because backup infielder Ryan Theriot was unavailable due to an illness.

The Giants finished with three errors, giving them 19 in 14 games this season. They came into the day with the most in the majors.

NOTES: Giants ace Tim Lincecum, off to a terrible start, is scheduled to pitch Sunday against RHP Dillon Gee (1-1, 2.92 ERA) — though rain is in the forecast. Lincecum is 0-2 with a 10.54 ERA in three outings, allowing 22 hits in 13 2-3 innings. "It's more confidence right now," Bochy said. "There's nothing mechanical wrong with him." The two-time Cy Young Award winner is 3-0 with a 0.41 ERA in his last three starts against the Mets, yielding one earned run in 22 innings. ... Theriot was flying from San Francisco to New York on Saturday but apparently wasn't available off the bench. ... Mets prospect Matt Harvey, drafted seventh overall in 2010, earned his first Triple-A win Friday night. He matched a career high with 10 strikeouts, including Bryce Harper twice. ... Before the game, fans and their dogs paraded around the warning track as part of the Bark in the Park promotion. Attendance was 33,844, plus 429 dogs.