NEW YORK (AP) For seven innings Thursday night, Zack Wheeler looked like he was going to go into free agency with a flourish. But then Curtis Granderson stepped to the plate and came up with his own ending.

Granderson's go-ahead, pinch-hit homer capped a three-run eighth inning against his former team and lifted the Miami Marlins to a 4-2 win over the New York Mets.

The pinch-homer was the fourth of the season for Granderson, who played for the Yankees from 2010-13 before joining the Mets from 2014-17. The 38-year-old Granderson, who is batting .187 as a reserve for the Marlins, said earlier this week he hopes to play again in 2020.

''If it's going to be his last one here, I'm so glad that happened,'' Marlins manager Don Mattingly said. ''We'll see where that goes. But if it was it, it was a really nice moment. And good for us.''

The fans at Citi Field acknowledged Granderson might be playing the final week of his career with a series of warm ovations during each of his four pinch-hitting appearances this week.

''If it does end up being that way, that'd be a really, really cool way to go out,'' Granderson said. ''But who knows what ends up happening?''

The same question can be asked of Wheeler, who is headed into free agency following seven up-and-down seasons with the Mets.

Wheeler, acquired from the San Francisco Giants for Carlos Beltran in 2011, missed two seasons recovering from Tommy John surgery but has gone 23-15 with a 3.65 ERA over 60 starts the last two years.

Wheeler (11-8) ended this season by throwing at least seven innings in each of his final four starts.

This time, Wheeler allowed two hits through seven innings and broke a scoreless tie with an RBI single in the bottom of the seventh, when Brandon Nimmo added a sacrifice fly for a 2-0 lead.

''When I sent him up to hit, I was like, `He's going to get a hit and he's going to throw two more innings and he's going to go into free agency scoring the only runs and throwing a shutout,''' Mets manager Mickey Callaway said. ''And that would have been great.''

But Wheeler, who had allowed only two hits at that point, gave up a leadoff double to Harold Ramirez. One out later, rookie Tyler Heineman tied the game with his first career homer. Granderson, pinch-hitting for winning pitcher Jeff Brigham (3-2), followed with his homer.

Wheeler, who struck out 10 and walked none, said he wasn't thinking about the possibility he was making his final appearance with the Mets.

''It was kind of like it's been all year: Just concentrate on this lone start,'' Wheeler said. ''Whatever happens, it is what it is, but my mindset's here, just trying to win a ballgame.''

Austin Dean hit a solo homer in the ninth off Edwin Diaz.

Brigham recorded the final out of the seventh. Jose Urena earned his third save with a one-hit ninth.

Marlins starter Jordan Yamamoto allowed one hit and walked three while striking out a career-high 10 over six innings.

BIG WEEK IN THE BIG APPLE

Heineman's homer capped a memorable series for the rookie, who collected his first big league hit Wednesday by doubling off Cy Young Award winner Jacob deGrom. Heineman received an autographed baseball from deGrom Thursday and got some help retrieving the home run ball later in the evening from Mets right fielder Michael Conforto.

''I think it landed on the netting (then fell on the field) and then Conforto threw it up into the stands,'' Heineman said. ''And then he comes up the next inning. He goes `Hey, congratulations, by the way, I threw up your home run ball by accident. But then I told somebody, like security, to grab it.' And I said `Thank you and I appreciate it.'''

Heineman's younger brother, Scott, is a member of the Texas Rangers and hit his first career homer against the Yankees at Yankee Stadium on Sept. 3.

ALONSO'S A LEADER ... AND A LEADOFF MAN?

Callaway said he and bench coach Jim Riggleman have discussed batting Pete Alonso first over the weekend in order to give the slugger additional chances to tie or break Aaron Judge's single-season rookie home run record of 52. Alonso is one homer shy of matching Judge after striking out in all four plate appearances.

Callaway said his biggest concern is accidentally hurting Alonso's chances by putting him into the unfamiliar spot atop the lineup. Callaway said Riggleman has tried that in the past during his managerial stints.

''Sometimes, it puts you in a position where you're kind of uncomfortable. So all of a sudden, you're leading off and you've never done it before. And we don't want Pete to feel that,'' Callaway said.

''Now, I'm not saying if I talk to him after tonight that it's not possible, because it could happen,'' he said.

TRAINER'S ROOM

Marlins: Yamamoto made his second start since missing almost a month with a right forearm strain.

Mets: OF/1B Dominic Smith (left foot) was activated from the 60-day injured list. Smith, who hasn't played since July 26, will likely be limited to pinch-hitting and defensive replacement duties down the stretch. INF/OF Jeff McNeil (broken right ulna) was placed on the 60-day IL ... 2B Robinson Cano left the game after being hit in the right arm by a pitch in the eighth inning.

UP NEXT

Marlins: RHP Pablo Lopez (5-8, 4.96 ERA) will look to earn his first win since June 15 when he closes out his season in the opener of a three-game series at Philadelphia.

Mets: RHP Marcus Stroman (9-13, 3.23 ERA) will make his 11th start since being acquired from the Toronto Blue Jays on July 28.

---

More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports

Copyright 2019 by STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.