MIAMI -- Casey McGehee singled off the leg of reliever Gonzalo German in the bottom of the ninth as the Miami Marlins rallied to defeat the New York Mets 4-3 Monday night at Marlins Park.

It was the Marlins' second walk-off win in two games.

McGehee, a third baseman, singled to score left fielder Christian Yelich, who had singled and was sacrificed to second on a bunt by second baseman Ed Lucas.

The Mets were up 3-0 until Mets reliever Daisuke Matsuzaka gave it all back with a shaky performance in the eighth. He walked the first two batters and gave up a rocket-shot, run-scoring single up the middle to right fielder Giancarlo Stanton.

A second run scored when McGehee hit a low liner to Mets shortstop Omar Quintanilla, who let the ball glance off his glove for an error.

The Marlins then tied the score 3-3 on catcher Jarrod Saltalamacchia's double.

That brought in reliever Kyle Farnsworth, who got out of a no-out, second-and-third jam. He got a groundout with the infield in, intentionally walked a batter to load the bases and struck out shortstop Adeiny Hechavarria looking.

With two outs, the bases loaded and a 3-2 count, Farnsworth induced center fielder Marcell Ozuna to hit an inning-ending groundout.

Miami (17-15) won the battle between NL East rivals and improved to 15-5 at home. That's the best home record in the majors this season.

New York (16-15) fell to 2-4 on a road trip that ends Wednesday in Miami.

For the first seven innings, it appeared the Mets would win fairly easily. Mets left-hander Jon Niese pitched seven scoreless innings and never allowed a runner past second base.

It was the fourth stellar start in a row for Niese, who allowed one run each time out against the Phillies, Cardinals and Braves.

Niese got a no-decision, which is the same thing that happened to Marlins starter Nate Eovaldi, who set a career-high with 10 strikeouts in seven innings. Eovaldi allowed five hits, one walk and three runs.

The Mets, no doubt following a trend in which Eovaldi had allowed left-handed hitters to bat .325 against him this season, stacked their lineup that way, and it paid dividends with early home runs from second baseman Daniel Murphy and center fielder Curtis Granderson.

Entering the game, right-handed hitters were batting just .127 against Eovaldi. That's why just two right-handed hitters were in the Mets' lineup -- third baseman David Wright and catcher Travis d'Arnaud. And that's why the Mets gave rare starts to lefty hitters such as right fielder Bobby Abreu and Quintanilla.

The Mets opened the scoring in the first when Murphy and Granderson pulled low-and-inside pitches to right field for home runs.

New York made it 3-0 in the fourth when Wright hit a leadoff double to left, advanced to third on Granderson's sharp single to right and scored on Abreu's sacrifice fly.

NOTES: Marlins RHP Jose Fernandez said Monday he is fine and he will not miss a turn after being hit by a batted ball Sunday in Miami's 5-4 win over the Los Angeles Dodgers. Fernandez said he has a bruise on his left thigh. ... Fernandez was selected the National League Pitcher of the Month after going 4-1 with a 1.59 ERA in April. He limited hitters to a .174 average and struck out 12.48 batters per nine innings. ... Miami rested CF Marcell Ozuna, moving LF Christian Yelich to his spot. Reed Johnson started in left. Ozuna entered the game as a pinch hitter... With the Mets throwing LHP Jon Niese, Miami sat left-handed-hitting Garrett Jones and used right-handed-hitting Jeff Baker at first base. ... The three-game series continues Tuesday when Miami throws RHP Henderson Alvarez against Mets RHP Bartolo Colon.