Several times, the Mets have looked cooked. On multiple occasions, Todd Frazier’s time with the club appeared to be coming to an end.

The Mets would go on long losing stretches, flirting with irrelevance. The veteran third baseman from New Jersey would go weeks without meaningful offensive production, drawing calls for his benching.

And, yet, here they both are, still playing meaningful baseball the second week of September, very much alive in the wild-card race. In many ways, these Mets and Frazier are mirror images of one another. Maddeningly inconsistent but unwilling to let this roller-coaster season go, producing unlikely moments of joy.

“He’s a pro’s pro and he’s one of our leaders,” manager Mickey Callaway said. “When he’s going good, we are a really, really good team.”

The recent uptick continued Wednesday night, with the suddenly resurgent 33-year-old Frazier leading the charge for a second straight night and Steven Matz continuing his stellar pitching in Queens. Frazier homered twice — in his first two at-bats — as the Mets hammered the Diamondbacks, 9-0, winning for the eighth time in 12 games following that six-game Citi Field losing streak most thought would ruin them.

“As a teammate, Todd’s the man,” Pete Alonso said. “He’s been there a lot for me. He’s awesome. He picks up his teammates. … He’s been a real anchor for us all year I feel like.”

Frazier led the offensive onslaught that included five home runs — two also from Jeff McNeil — and netted the Mets nine runs on 11 hits on, of all nights, the 18th anniversary of 9/11.

“How cool is that?” Callaway said. “A little destiny for the day.”

A free-agent-to-be and likely at the end of his Mets career, Frazier began this series an afterthought, not appearing in Monday’s 3-1 victory after pinch hitting the day before. Mets fans were furious when he was back in there, in place of J.D. Davis, on Tuesday — Frazier had managed back-to-back multi-hit games just once since late June — before he produced all three runs with a pair of doubles. On Monday, the team seemed stuck in neutral, following up road series wins over the Phillies and Nationals, by losing two of three at home over the weekend to Philadelphia.

But after winning the first three games of this series against the previously red-hot Diamondbacks, holding their potent lineup down three nights in a row, the Mets (75-70) moved within two games of the Cubs and Brewers for the second wild card. They have jumped over Arizona and pulled even with the Phillies.

“Just as a group, we don’t let the past affect us too much,” said Matz, who allowed four hits and struck out seven over six shutout innings. “That’s all we can control — what we do moving forward.”

Unlike the previous two games, the Mets didn’t have to sweat, thanks in part to Arizona left fielder Tim Locastro’s first-inning gaffe. With a run already in, he misread Davis’ line drive, allowing it to drop and a second run to cross the plate. Three pitches later, Frazier went deep, pushing the lead to 4-0, and Brandon Nimmo followed with his own homer, a solo shot. In the third, Frazier blasted his 20th of the year, sending a 95 mph Taylor Clarke fastball low and away over the right-center field fence, a sign of how hot he has suddenly become.

The Mets have followed his lead the past two nights and can sweep the Diamondbacks out of Queens on Thursday.

“I always tell the guys, don’t ever beg, but always get greedy,” Frazier said. “Let’s not treat it as a sweep. Let’s treat it as winning that day. As you see, a couple of teams are winning, a couple of teams are losing. It’s going up and down.”

Purchase event tickets to The Amazin’ 1969 New York Mets: A World Championship for the Ages presented by The Paley Center for Media and New York Post. Enter promo code: NYPOST to unlock tickets only available for Post readers.