Gallardo (5-7) earned his first victory as a starter since June 12. He gave up five hits, walked two and struck out two.
The veteran right-hander was sent to the bullpen after a June 17 loss in Texas and didn't return to the rotation until last weekend against the New York Yankees. He got a no-decision in that game despite leaving with a lead after five innings.
DeGrom (12-4), who had won eight straight starts, allowed three runs (two earned) and five hits in six innings. He struck out 10 and walked one. It was deGrom's eighth game with double-digit strikeouts in 21 starts this year.
Seattle's Tony Zych, Marc Rzepczynski and Nick Vincent combined for 2 1/3 scoreless innings of relief before turning it over to closer Edwin Diaz in the ninth.
Wilmer Flores doubled to lead off the inning and advanced to third on a groundout. Michael Conforto, the Seattle native who hit two home runs the previous night, singled to right field with two outs to drive in Flores. Diaz struck out Asdrubal Cabrera to end the game and post his 19th save of the season.
There was damage done in the bottom of the second inning -- to both teams.
Nelson Cruz led off by lining a pitch off deGrom's left shin. The ball struck the right-hander so hard it caromed into shallow right field. Manager Terry Collins and the Mets' training staff checked on de Grom, but he was able to continue.
Kyle Seager followed with a double to right-center field, putting runners at second and third. DeGrom struck out Danny Valencia, but then came the second scary moment of the inning.
DeGrom threw a 95 mph fastball that rode up and in on Mitch Haniger, hitting him in the mouth.
Mets catcher Travis d'Arnaud immediately tended to Haniger as Mariners manager Scott Servais and trainer Rick Griffin raced from the dugout. Cruz could be seen standing on third base with his head in his hands as a hush came over the crowd.
Haniger was able to get up and walk off the field with help from Griffin and was replaced by pinch-runner Guillermo Heredia, loading the bases. The Mariners later announced Haniger suffered a mouth contusion and had been taken from the ballpark for further examination.
Jarrod Dyson followed with a two-run single to right field, snapping the scoreless tie. Dyson stole second to put runners at second and third, but deGrom got out of the inning by striking out Mike Zunino and Jean Segura.
The Mariners added another run in the third as Ben Gamel led off with a single, extending his hitting streak to 15 games. Robinson Cano then hit a grounder to second baseman Neil Walker, who tried to get a force on Gamel, but his throw was errant, allowing Gamel to take third. Cruz followed with a sacrifice fly to left field to make it 3-0.
The Mariners nearly had another run in the inning, but Conforto made a lunging, over-the-shoulder catch of a ball hit to left by Seager. Conforto also threw out Seager attempting to score to end the eighth inning.
The Mets finally scored in the sixth.
With two outs, Yoenis Cespedes and Walker singled, knocking Gallardo from the game.
After Zych allowed a leadoff single to d'Arnaud in the seventh, Rzepczynski entered and walked Conforto. But the left-hander got Cabrera to ground into a double play and struck out Jay Bruce to end the inning.
Vincent pitched a perfect eighth for the Mariners before handing the ball to Diaz in the ninth.
NOTES: Former Miami closer A.J. Ramos, acquired by the Mets late Friday night for two minor leaguers, is expected to be available out of the bullpen Sunday. ... Mets fans took up a couple of sections in the right-field corner of the first deck, wearing orange T-shirts that read "Queen's Court," in response to the Mariners' "King's Court" in the opposite corner when longtime ace "King" Felix Hernandez pitches. ... Mets RHP Seth Lugo (5-2, 4.10 ERA) is scheduled to face Mariners LHP James Paxton (10-3, 2.84) on Sunday afternoon in the finale of the three-game interleague series.