NEW YORK (AP) -- Worn down and visibly frustrated on the bench, the New York Mets were in danger of dropping another discouraging game.
Beltran hit a two-run homer with two outs in the 13th inning, and New York overcame a blown save by Wagner to snap a five-game losing streak with a 5-3 victory over the Arizona Diamondbacks.
"It was a big team win. Guys picked each other up," Wagner said. "We're tired. We've battled. It's just one of those situations where we continuously fight."
The Mets chased a bruised Brandon Webb early and took advantage of a key error by third baseman Mark Reynolds, who tied it by hitting a three-run shot off Wagner with two outs in the ninth for his fourth home run in four games.
That cost Mike Pelfrey a win in the best outing of his big league career, but New York refused to fold and avoided falling four games below .500 for the first time since Sept. 17, 2005, according to the Elias Sports Bureau.
"I feel sorry for Pelfrey because he pitched a great game," said Beltran, who also hit a two-run single in the fourth. "Tonight, we'll sleep good."
Luis Castillo hit a hard one-hopper into Reynolds' midsection with one out in the 13th and reached safely when the ball trickled away.
David Wright fouled out but Beltran lined a 1-2 pitch from Edgar Gonzalez (1-3) to right-center for the fifth game-ending homer of his career and first since Aug. 22, 2006, off St. Louis reliever Jason Isringhausen.
Exhausted-looking Mets poured out of the dugout to celebrate at the plate, mobbing Beltran and bouncing in unison.
"Fastball up, in the middle of the plate. I just reacted to it," Beltran said. "I wasn't sure it would be gone because it was on a line."
Looking for his first win in 10 starts, Pelfrey outpitched Webb and took a four-hit shutout into the ninth. He was pulled after Stephen Drew's leadoff single on his 112th pitch and received a rousing ovation from the crowd of 46,503.
Wagner struck out Orlando Hudson before Jackson's double put runners at second and third. Chad Tracy struck out but Reynolds, who fanned all three times up against Pelfrey, drove a full-count fastball 420 feet into the left-center bleachers for his 15th home run.
That brought a chorus of boos directed at Wagner, who also served up a go-ahead, three-run homer to pinch-hitter Tony Clark in Sunday's 8-6 loss at San Diego.
This time, a frustrated Wagner tossed his head back and looked to the sky as Reynolds' drive sailed out. Pelfrey showed no emotion at all, staring straight ahead with his chin resting on the dugout railing.
It was Wagner's fourth blown save in 17 opportunities this season.
At that point, "You think the momentum is in our dugout," Diamondbacks manager Bob Melvin said.
Hit on the right hip by Carlos Delgado's line-drive single during a three-run fourth, Webb departed for a pinch hitter in the sixth. The right-hander threw 40 of his 58 pitches for strikes.
"I'll be all right tomorrow. It's just a bit sore. It hurt for a moment," Webb said. "I've been throwing a lot of pitches, a lot of innings. I didn't have my best stuff. He gave me a chance to throw a short game and recover. Maybe I'm going through a dead arm a little -- my velocity is down. And Pelfrey was throwing a great game."
In the eighth, Pelfrey was humming at 95 mph. He set career highs by striking out eight in eight-plus innings.
Webb, who leads the majors with 11 wins, has a 1.06 ERA in five career games at Shea Stadium. He beat Pelfrey 10-4 on May 3 in Arizona.
Pelfrey is 0-6 in 10 starts since beating Washington 6-0 on April 15, though he carried a no-hit bid into the seventh May 15 against the Nationals and still lost 1-0.
The 24-year-old right-hander, selected ninth overall in the 2005 draft, has allowed only four runs in his past three starts spanning 21 innings.
"Now we see what he's capable of," Mets catcher Brian Schneider said. "We've been playing good baseball and it's time for us to get some bounces."
Pelfrey even singled in the fifth, snapping an 0-for-22 stretch to start the season. But manager Willie Randolph made a curious move by letting the pitcher bat leading off the eighth.
The crowd liked it at least, chanting Pelfrey's name and cheering him wildly after he struck out.
"The bottom line is we won the ballgame," Randolph said.
Jackson, normally Arizona's first baseman, started in LF for the first time this season. ... Mets SS Jose Reyes turned 25.
Mina Kimes calls out Mets' workplace culture
Mina Kimes wants Mets staffers held accountable for their inappropriate workplace behavior.
Buehler expected to start for Los Angeles at San Diego
Los Angeles Dodgers (11-2) vs. San Diego Padres (9-5)
Fantasy baseball forecaster: Team hitting ratings
Stay ahead of the game and optimize your fantasy baseball hitters with our forecaster, which provides a rolling 10-day outlook of every team's hitting matchups as well as the potential for stolen bases.
Fantasy baseball forecaster: Pitcher projections for the next 10 days
Keep up to date on who is pitching -- and how well they're expected to do -- with our forecaster, which provides a rolling 10-day outlook of every team's probable starting pitchers with game score projections.
Fantasy baseball forecaster for Week 3: April 19-25
Set your lineups for the week ahead in fantasy baseball with our forecaster preview, which features pitcher rankings, two-start pitchers, hitter ratings, schedule observations and more.
Viral Phillies fans get surprise FaceTime from Bryce Harper
Phillies superfans Josh and James Scott receive a surprise call from Bryce Harper after going viral in the game against the Braves.