NEW YORK — That new Marlins lineup looked wonderful — for all of one inning.

Curtis Granderson came off the bench and homered twice, Jose Reyes had four hits and the New York Mets beat Miami 7-4 on Tuesday night.

Trying to spark a slumping offense, Marlins manager Don Mattingly shuffled his 2-3-4 hitters and moved up Xavier Scruggs from seventh to fifth. It worked right off the bat, with Christian Yelich hitting a two-run homer in his first career plate appearance batting cleanup.

“To get two runs on the board felt good. I didn’t think it had anything to do with necessarily where we’re hitting him in the order,” Mattingly said.

It was the team’s first home run in eight games, but that was all for the Marlins until J.T. Realmuto hit a solo homer in the ninth. Jeff Francoeur tripled with two outs and scored on Dee Gordon’s single before Jeurys Familia struck out Marcell Ozuna for his major league-leading 43rd save in 46 chances.

New York has won nine of the past 12 meetings this season. By taking the first two games of this four-game series, the Mets (68-64) passed Miami for second place in the NL East.

The defending NL champions remained 2 1/2 games behind St. Louis for the league’s second wild card.

Meanwhile, the Marlins have dropped four straight and six of eight overall.

“We can’t try to fix it overnight. It’s not going to work that way. We’ve just got to play good ball,” starter Tom Koehler said.

Koehler (9-10) had to throw extra pitches in the fifth because Alejandro De Aza reached after striking out on a wild pitch with two outs.

Realmuto blocked the ball and it rolled only a few steps away, but he took his time picking it up and was caught off guard by a hustling De Aza.

“We’ve seen that a couple times from J.T.,” Mattingly said. “It’s something we’ll talk about. … It’s one of those things where you’d like to see a little more sense of urgency there. We can’t take any chances of giving any outs away.”

Koehler, who grew up in nearby New Rochelle, allowed five runs and a career-high 10 hits in five-plus innings. He fell to 2-7 with a 4.37 ERA against the Mets.

The right-hander has lost two straight after going 3-0 in his previous six starts.

“They came out very aggressive today. Lot of first-pitch base hits. Never really allowed me to get into a rhythm,” he said.

Asdrubal Cabrera added to his recent tear at the plate, hitting a two-run homer after missing one start with a sore knee. Rookie right-hander Seth Lugo (2-2) gave up Yelich’s homer in the first inning but recovered nicely as the Mets won for the eighth time in 10 games.

Granderson, batting for Lugo, connected for his second career pinch-hit homer leading off the sixth, extending New York’s lead to 4-2 with the club’s ninth pinch-hit homer this season.

De Aza added an RBI single later in the inning off Dustin McGowan.

Granderson, who stayed in to play right field, launched a two-run shot in the seventh.

Reyes singled leading off the first and Cabrera went deep on the next pitch. It was the 17th home run this season and fourth in 11 at-bats for the reigning NL player of the week. He is batting .447 with four doubles and 11 RBIs in 11 games since coming off the disabled list Aug. 19.

Reyes and Cabrera got on base seven times in 10 combined plate appearances from the top two spots in the lineup.

Slumping slugger Jay Bruce, who started over Granderson, doubled later in the first and scored on a two-out single by Wilmer Flores that gave the Mets a 3-2 lead.

Lugo went six innings and retired the final eight batters he faced in his third major league start.

END OF THE LINE

Seven of Familia’s saves this year have come against Miami — most for any major league reliever versus one team.

TRAINER’S ROOM

Marlins: LHP Adam Conley (finger tendinitis) began a throwing program in Florida. It could take him about three weeks to return, Mattingly said. … RHP Andrew Cashner (finger blister) played long toss and is scheduled to throw a bullpen Wednesday. He remains on track to start Friday in Cleveland, according to Mattingly. … RHP A.J. Ramos was OK after crashing into Reyes on a play at the plate Monday night, Mattingly said.

Mets: Rookie LHP Steven Matz (shoulder) is not ready to come off the disabled list and was scratched from his scheduled start Thursday night. Jacob deGrom will be moved up a day to start for Matz in the series finale, manager Terry Collins said.

UP NEXT

Marlins RHP David Phelps (7-6, 2.52 ERA) starts Wednesday night against 43-year-old RHP Bartolo Colon (12-7, 3.44 ERA).