The decision completed a three-game interleague sweep for the Mets, who head home for a nine-game stand that includes visits from Cincinnati, Baltimore and the New York Yankees.
Nieuwenhuis hit the second pitch of the game for a home run but it was his fourth-inning, two-run homer that broke a 4-4 tie and gave the Mets the lead for good. He has five home runs this year.
Johan Santana (4-3) gave up four runs on six hits and four walks in six innings but still got the win. Rays starter Jeremy Hellickson (4-3) was charged with eight runs on nine hits in 3 2/3 innings in the loss.
Jason Bay put New York up 2-0 with a home run in the second, but the Rays answered with a three-run rally that included a two-RBI double by Matt Joyce. Duda and Ike Davis drove in runs in the New York third but Ben Zobrist had an RBI double for Tampa Bay to make the score 4-4.
Nieuwenhuis hit his fourth-inning home run with two out and Duda added a two-run double in the fourth-run fourth.
Davis drove in David Wright, who had three hits and scored three runs, in the ninth. The Rays made it interesting with a pair of ninth-inning runs but leaving three other runners on base when Frank Francisco struck out Zobrist on a full count to end the game and pick up his 16th save.