The Yankees, who are top of the American League (AL) with a 71-39 record, had been swept in a three-game series by the St Louis Cardinals along with two defeats to the Mariners at Yankee Stadium in their past five.
But they responded at T-Mobile Park from the outset, with Josh Donaldson hitting a first-inning two-run single along with a third-inning solo home run, sandwiched by Mitch Haniger's blast as the Yankees claimed an early 4-1 lead.
The Yankees pulled clear with three runs in the fifth inning, as Andrew Benintendi doubled on a line drive with Donaldson and Gleyber Torres scoring, followed by Benintendi from Isiah Kiner-Falefa's sac fly.
Judge, who leads the majors in home runs, RBIs, runs, slugging percentage and on-base plus slugging this season, re-discovered his form in the ninth inning after his recent lean stretch.
The Yankees outfielder had a close call with a high ball falling just short of the wall in the third inning, but blasted a solo home run in the ninth with a fly ball over deep center field.
The home run was Judge's 44th home run of the season, continuing his march to history with the AL single-season record of 61, from Roger Maris in 1961, within sight. It also ensures Judge's longest run without a home run this season remains seven games.
More Mets momentum with Reds win
Starling Marte crushed a two-run home run in the first inning off ex-Mets pitcher Justin Dunn, but Francisco Lindor was sensationally denied a fifth-inning blast by a leaping Albert Almora with a high catch on the wall. Tyler Naquin's eighth-inning two-RBI triple sealed the win.
Chris Bassitt sent down eight strikeouts across eight innings for the Mets, whose starters have pitched a league-best 2.21 ERA since July 5. The Mets have won 13 of their 15 games.
Orioles maintain Wild Card push
The in-form Baltimore Orioles boosted their AL Wild Card aspirations with a 7-4 victory over the Toronto Blue Jays.
Felix Bautista closed out the victory, with Bo Bichette grounding into a double play, as the O's improved to 57-52 in the AL Wild Card hunt behind the Blue Jays (60-49), Tampa Bay Rays (58-50) and Mariners (59-52).