With the Yankees trailing 3-0 at the bottom of the fourth inning, Judged lined a drive over left field to cut the deficit with a solo blast.
The drive meant Judge has the most home runs in a single season in Yankees' history for a right-hander, breaking a tie with Alex Rodriguez.
Judge homered for a fourth straight game, keeping him on track to surpass Roger Maris' Yankees record of 61 blasts in a single season set in 1961, exceeding Babe Ruth's 60 in 1927.
In the sixth inning, the Yankees leveled the game before two runs in the 12th capped by Oswaldo Cabrera's game-ending single.
The Yankees also won 7-1 in the second game of the double-header to improve their record to 83-54, sitting five games ahead of the Tampa Bay Rays in the American League East.
Soto injured as Padres win
Soto was struck and floored by a wild 91 mph fastball from Diamondbacks pitcher Tommy Henry at the bottom of the third inning. He walked to first base, fielded in the fourth inning but eventually was taken out of the game in the fifth.
Cards rally in walk-off win
With runners on first and second base, Edman drove to left field, resulting in a walk-off two-run double.