T.J. Rivera settles in at second base after his tying...

T.J. Rivera  settles in at second base after his tying two-run double in the seventh inning on the way to an 8-7 victory over the Miami Marlins at Citi Field on Friday, May 5, 2017. Credit: Brad Penner

T.J. Rivera reached second base, clapped his hands hard and savored the moment.

The Mets had appeared on the brink of certain defeat, staring at a six-run deficit against the Marlins. But when circumstance brought Rivera to the plate in the seventh inning Friday night, he didn’t miss his chance, ripping a two-run double to tie the score in what became a stirring 8-7 victory for the Mets at Citi Field.

Wilmer Flores drew a bases-loaded walk to force in the go-ahead run later in the five-run seventh, but it was Rivera who powered the Mets, tying his career high with three RBIs.

“It’s a great feeling to know that you came through in a situation that the team needed you,” said Rivera, who has shined in place of injured first baseman Lucas Duda. “I think any player would say that. To drive in those runs and tie the game, it felt good. So I let a couple of emotions out.”

After the Marlins chased an overmatched Rafael Montero in the fourth, the Mets trailed 7-1, with their only run coming on Rivera’s first-inning homer. It proved to be a mere preview of his later heroics.

The outburst was part of a surprising surge by the Mets (13-15), who have scored at least five runs in eight straight games. Even without Yoenis Cespedes and Noah Syndergaard, they have won five of their last seven.

The comeback was the Mets’ biggest since July 4 last season, when they rallied from a 6-0 deficit to beat the Marlins.

The Mets had hitched their hopes to the power of their arms, with all of their aspirations flowing from a rotation that they envisioned would smother the rest of the National League. This had always been the plan, but injuries and ineffectiveness changed everything.

Which is why Montero took the mound, given another opportunity to prove that he’s worthy of staying in the major leagues at a time when his team needs him. But the only thing he did was invite more doubt.

In 3 2⁄3 innings, he showed all of the timid traits that have kept him from realizing his potential. Hitters laid off close offerings, leading Terry Collins to wonder if Montero is tipping his pitches. With his spot in the rotation assured only because the Mets have no other options, the righty allowed five runs and seven hits. But the Mets made sure that would be a problem to ponder another day.

The comeback began with Curtis Granderson hitting a two-run homer in the bottom of the fourth that shaved the Mets’ deficit to 7-3.

New York Mets centerfielder Curtis Granderson celebrates with teammates after...

New York Mets centerfielder Curtis Granderson celebrates with teammates after hitting a two-run home run against the Miami Marlins during the fourth inning at Citi Field on Friday, May 5, 2017. Credit: Brad Penner

After Marlins reliever Brad Ziegler inherited that lead in the seventh, Flores singled, Jose Reyes doubled, Rene Rivera singled home a run and Asdrubal Cabrera, who had been benched to rest his weary legs, singled in another.

Michael Conforto singled up the middle to load the bases. That brought up T.J. Rivera, who lined a double to leftfield past Marcell Ozuna to tie the score. Just like his homer, it came on the first pitch.

“He doesn’t draw walks,” said Collins, who moved Rivera to the second spot in the lineup based on recent success. “He hits.”

The Mets value plate discipline, working deep into counts, all in hopes of hitting for power. But Rivera works with the opposite mentality, unafraid to be aggressive. For now, it’s exactly what the Mets have needed.

“I have to be confident in my ability to hit the ball and just stick with my approach, and that is to put the bat on the ball,” said Rivera, who is hitting .407 in his last seven games. “I’m not going to walk much.”

Newsday LogoDON'T MISS THIS LIMITED-TIME OFFER1 5 months for only $1Save on Unlimited Digital Access