The Red Sox (59-39) are seven games ahead of the fourth-place Yankees (51-45) in the AL East.
Ellsbury hit a solo home run in the first inning and Gomes added a two-run homer in the second at Fenway Park in Boston.
Brett Gardner stole third and scored on a throwing error by Red Sox catcher Jarrod Saltalamacchia to give the Yankees their first run in the fourth inning. Chris Stewart added a run-scoring double in the fifth as the Yankees pulled within 3-2.
Gomes scored on Jose Iglesias’s single in the seventh inning.
New York’s Gardner was ejected in the top of the fifth after he was called out on strikes on a 3-2 pitch and slammed his helmet to the ground.
Felix Doubront (7-3) struck out five while allowing two runs on three hits in 6 1/3 innings. Koji Uehara got his ninth save, striking out one in the final inning.
Andy Pettitte (7-7) gave up four runs on six hits in 6 1/3 innings for the Yankees.
Earlier yesterday, the Yankees placed shortstop Derek Jeter on the disabled list with a strained quadriceps muscle, an injury the team captain suffered in his only major league game this season.
Jeter, 39, returned from offseason ankle surgery on July 12, only to sustain the low-grade strain of his right quadriceps. He was placed on the 15-day disabled list retroactive to the day of the injury, the Yankees said in a news release.
The team promoted infielder Brent Lillibridge from the minors, placing him on the team’s 40-man roster.
Alex Rodriguez could return to the Yankees’ roster for the first time this year no later than July 23. The third baseman, who had hip surgery in January, is finishing his rehabilitation stint this weekend at the team’s Triple-A Scranton/Wilkes-Barre Railriders.
To contact the reporter on this story: Nancy Kercheval in Washington at firstname.lastname@example.org
To contact the editor responsible for this story: Michael Sillup at email@example.com