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.
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, Carlos Delgado was hit by a pitch and Beltran pulled the first pitch over the right-field wall.
Luis Ayala earned his third save despite giving up four hits in the ninth, including an RBI single by pinch-hitter Mike Jacobs and a run-scoring double by Jorge Cantu. Wes Helms grounded out with runners at second and third to end the game.
Joe Smith (2-3) pitched a scoreless eighth. Beltran's homer was his 20th, and he drove in all five New York runs.
The grand slam left the third-place Marlins reeling at the start of a big weekend series. 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.
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.
The Mets' 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.