The Red Sox had lost their two games prior to the All-Star break, but four pitchers limited the Yankees to five hits and one earned run.
Ellsbury hit a solo homer in the first and Gomes added a two-run shot in the second in support of Felix Doubront (7-3).
Doubront went 6 1/3 innings, allowing both New York runs on three hits with five strikeouts. Koji Uehara needed just seven pitches to get through the ninth for his ninth save.
Andy Pettitte (7-7) was charged with the loss after surrendering four runs on six hits in 6 1/3.
New York has dropped three in a row and six of its last nine.
Swim Week Miami Beach 2014 [PHOTOS]