Before Beltran's homer, the Mets were 1-for-7 with runners in scoring position. Trailing 2-1, they left the bases loaded in the seventh and stranded two in the eighth.
"We didn't score early, but we scored when the team needed it the most," Beltran said.
Gregg (6-8) retired the first two batters in the ninth, and New York was down to its final strike when Luis Castillo singled on a 1-2 pitch. David Wright also singled, and Carlos Delgado was hit by a pitch to load the bases for Beltran.
"I wasn't looking for anything in particular," Beltran said. "I was thinking, 'I just need to come through right here and at least tie the game.' "
Gregg's first pitch was a hanging splitter, and Beltran pulled it over the right-field wall for his 20th homer.
"I knew it was going to be gone, and I was happy because this is a team we really need to beat," Beltran said.
The grand slam left the third-place Marlins reeling. They've been fading in the NL East and fell seven games behind the Mets, who increased their lead over second-place Philadelphia to two games.
"Our backs are against the wall," Florida outfielder Cody Ross said. "We've got to win. We've got to start tomorrow."
Gregg has contributed to the Marlins' slump. In his past seven outings he's 0-4 with an ERA of 16.20.
"It's a situation where I'm killing the guys," Gregg said. "They're playing good baseball, and I screwed it up. My last few outings have been horrible."
Manager Fredi Gonzalez ducked a question regarding whether he'll replace Gregg as closer.
"Anything else?" Gonzalez said. "I don't have to answer."
The Mets have had bullpen woes of their own, and Luis Ayala earned his third save despite giving up four hits in the ninth. Pinch-hitter Mike Jacobs singled in one run, and Jorge Cantu doubled home another before Wes Helms grounded out with runners at second and third to end the game.
That allowed Ayala to shrug off his wobbly outing.
"We won," he said. Ayala, who had ice taped to his right thigh, said he pitched with a tight hamstring.
Rookie Chris Volstad, facing the Mets for the first time, limited them to five hits and one run in 6 1/3 innings. New York's Oliver Perez was nearly as good -- he allowed the Marlins three hits and two runs, one earned, in six innings.
"We keep the team in the game, because we understand we have a really good offense," Perez said.
It was held in check for most of the night, with the Mets stranding 10 runners.
Their frustrations began in the first, when Florida third baseman Helms made a spectacular catch to end a threat. With two on and two out, he retreated and crossed the left-field foul line to make a backhanded catch of a foul pop just before he hit the waist-high retaining wall. Helms tumbled over the wall headfirst and landed in the Mets' bullpen but held onto the ball.
Jose Reyes and Castillo reached on consecutive infield hits to start the inning, and Beltran's sacrifice fly scored a run.
Florida's Josh Willingham hit his 10th homer leading off the second inning for a 1-all tie.
The Marlins scored without a hit in the third to take a 2-1 lead. Volstad reached on an error by shortstop Reyes. A walk and a fielder's choice sent Volstad to third, and he scored on a sacrifice fly by Cantu.
RHP Mike Pelfrey tries for his third consecutive complete game Saturday, but he's 0-3 with a 10.66 ERA in three starts this season against Florida. ... Dwyane Wade, wearing his Olympic gold medal, threw out the ceremonial first pitch. ... Perez has a 2.03 ERA in five starts against Florida this year.