Mets outfielder Kirk Nieuwenhuis ducked his head out of the dugout Sunday and raised his batting helmet into the air, the personification of a team that has known the darkness as well as the light.

He had struggled so badly that earlier this season, the Mets traded him to the Angels for cash, before reacquiring him when he wound up on waivers.

But all was forgotten during Nieuwenhuis' moment in the sun Sunday, earned after belting his third home run in the Mets' 5-3 victory over the Diamondbacks.

The Mets wrapped up their first half at 47-42, five games above the .500 mark, despite constant injuries and an offense that has habitually failed to support its stellar pitching.

They have won four straight overall and seven of their last nine, though they couldn't get through a day without another injury. Centerfielder Juan Lagares left the game in the ninth inning with what the team is calling tightness in his right calf.

"There's been some good things, there's been some rough things," manager Terry Collins said before the game. "But you know whatt We come out of the break, we're going to be in the hunt. And that's all we can ask for."

At the start of the day, the Mets stood just two games behind the Nationals for first place in the NL East, and just one game out of a wild card spot.

And nearly as inexplicably, they did it behind a career day by Nieuwenhuis, an .091 hitter with no homers this season when he found his name in the fifth spot of the lineup.

That predicament represented all that went wrong for the Mets in the first half. And his three-homer performance carried the same shock and awe of all the things that have gone right.

Nieuwenhuis became just the 10th Mets player in history to bash three home runs in a game, and the first since Ike Davis in 2012. The list of names also includes Jose Reyes, Gary Carter, Darryl Strawberry and Dave Kingman.

But only Nieuwenhuis accomplished the feat at home.

The Mets bashed four homers to complete a three-game sweep of the Diamondbacks, with Daniel Murphy adding a solo shot in the third inning

Otherwise, it was Nieuwenhuis who did all the damage.

His first home run, a solo shot off Rubby De La Rosa in the second inning, barely rose above the leftfield fence. In the third, Nieuwenhuis' two-run shot cleared the wall just left of straightaway center.

In the fifth, against reliever Randall Delgado, Nieuwenhuis watched his towering fly ball hit the screen of the rightfield foul pole. The Mets dugout exploded, with players raising their arms as they rushed the top step for a better view.

Moments later, Nieuwenhuis made his way up those same steps for an ovation. He later struck out in his bid to become the only Mets player to homer four times in a single game.

Nevertheless, the Mets have slammed 10 homers in their last four games after hitting just 11 in their previous 22 contests.

Lefty Jonathon Niese (5-8) extended his streak of quality starts to seven.

Niese held the Diamondbacks to three runs on five hits in 6 2/3 innings before giving way to Jenrry Mejia, who retired his only batter in his first outing since coming off his 80-game PED suspension.

Jeurys Familia recorded his 27th save.