The Mets had lost six of seven games to fall a season-worst five games below .500, and Thursday they faced Dodgers ace Zack Greinke, who was on a historic roll. Naturally, the Mets pulled out a 5-3 win to snap a three-game skid, avoid a sweep and ease some of the heat on manager Terry Collins.

And they did it in the unlikeliest of fashions.

Jonathan Niese (3-3) allowed just four hits and three runs in seven frames. The Mets snapped Greinke’s streak of consecutive starts allowing two runs or fewer at a major league-record 21 straight. And it was rookie Eric Campbell — who got his first big league start in left field because of his hot bat — who saved the day with his glove.

Juan Lagares reminded Collins why he’s an everyday player with an RBI single to snap a 3-all tie in the seventh off Chris Perez (0-2). In the next inning, Campbell — who got the start for struggling Chris Young — made a highlight-reel diving catch to rob Hanley Ramirez, then doubled Yasiel Puig off second to end the inning.

“Off the bat I thought it was going to be a one-hopper. I was charging to make a play at the plate. He hit it so well, it stayed up a little longer, and I was able to get my glove under it,’’ Campbell said.

“As it always goes, you put a guy in for his offense and his defense saves the game,’’ Collins said. “That’s a sign you were supposed to win.’’

The Mets have won only six of their 20 games this month, putting Collins under pressure. But Thursday they got contributions from youngsters such as Lagares and Jenrry Mejia, who pitched back-to-back days for the first time in four years to earn his second save of the season.

“I enjoy the bullpen: That’s my new house over there,’’ said Mejia, who is growing into the closer’s role, including celebratory postgame gyrations. “That’s no dance. Everybody asked me that. I never tried to dance. That’s adrenaline.’’

And why not? The Mets had overcome Greinke, making him expend 52 pitches in the first two innings and seeing him last just five frames, allowing four hits, two walks and three runs. Two were unearned, but the Mets gladly took them.

Curtis Granderson doubled in the first, took third on center fielder Matt Kemp’s bobble and scored on Campbell’s sacrifice fly. Then in the fifth, after Niese helped his own cause with an RBI double to plate catcher Anthony Recker, he scored when Justin Turner botched Daniel Murphy’s grounder for a 3-1 lead.

“I would’ve probably needed oxygen at third if I’d went [for a triple],” Niese said.

In the sixth inning, Murphy lost Ramirez’s popup in the lights for an error, and hesitated when the ball dropped in. Puig, thinking he was forced out, meandered off second and was tagged out. Even after Turner came back to haunt his former team with a two-run shot in the seventh to tie it, Lagares put the Mets in front in the bottom of the inning, and Campbell’s play helped preserve the lead.