MIAMI — Jason Vargas danced through trouble Tuesday night, using spacious Marlins Park and the anemic lineup he faced to his advantage.

Gifted five runs in the first inning, the veteran left-hander essentially put the ball over the plate and dared the Marlins to beat him. That led to plenty of hard-hit balls and traffic on the bases, but Vargas ultimately escaped in a 6-5 Mets victory.

The Mets (4-1) won their second straight series and can complete a three-game sweep on Wednesday with ace Jacob deGrom on the mound.

Vargas lasted five innings and allowed two earned runs on eight hits and one walk and then watched Robert Gsellman, Seth Lugo and Justin Wilson survive a final Marlins surge.

“I feel like throughout the game we either made the pitch we needed to at the right time or made the play we needed to in the right time,” Vargas said.

Wilson worked the final 1 ²/₃ innings for the save, getting Miguel Rojas to line into a game-ending double play with the tying run at second base. It came after Lugo, in a second straight sluggish performance, surrendered three runs over 1 ¹/₃ innings. Manager Mickey Callaway later said Lugo has battled illness in recent days that has sapped his energy.

Jeurys Familia and Edwin Diaz were both unavailable because of recent workload, limiting the manager’s bullpen options.

“This is the scenario that we walked through in my office before the game,” Callaway said. “Vargie gives us five and we are going to bring in that combination of three for the next four innings if we’re up and nail this thing down. It got a little hairy, but they came through in the end.”

Jose Urena barley survived a first inning for the Marlins in which the Mets scored five runs. The Mets padded their lead in the seventh when Brandon Nimmo was hit by a pitch with the bases loaded. Nimmo was drilled in the left hand as he started to swing and remained in the game to run the bases, but departed for a defensive replacement the following half inning.

Nimmo underwent preliminary X-rays on the hand that were negative, according to the Mets, but he will be reevaluated Wednesday.

“My first inclination would be that it’s not as serious as the two that happened last year,” said Nimmo, who spent time on the injured list following the second of those plunkings.

Starlin Castro’s solo homer in the fifth pulled the Marlins within 5-2, but Vargas managed to get the final out in the inning, after allowing a double to Martin Prado, and was removed at 74 pitches.

The Mets sent 10 batters to the plate in the first inning in racing to a 5-0 lead. After Michael Conforto walked to load the bases, Wilson Ramos and Dominic Smith each delivered RBI singles before Amed Rosario doubled in two runs. The inning’s fifth run scored on Juan Lagares’ RBI fielder’s choice.

Maybe the brilliance of the inning was the Mets continued their habit of hitting against the shift, content to reach base and put pressure on the defense.

“We need to get to the point where nobody shifts us,” Callaway said before the game. “When they are not shifting us anymore there are going to be openings on the left side or right side to get balls through there and once they stop shifting you hit balls through there, but you power a few balls.

“If we get enough groundballs through there they are going to have to stop shifting us and then you take more aggressive swings and the power starts to come.”

Smith was in the starting lineup for the first time this season, putting Pete Alonso on the bench a night after he smashed his first big-league homer, a three-run blast that contributed to a ninth-inning outburst. Alonso struck out in a pinch-hitting appearance in the seventh.