Tampa Bay starter Alex Cobb (9-9) had a 1-0 lead and was working on a no-hitter with one out in the sixth inning when he hit Boston's Jose Iglesias with a pitch.
One out later, Ellsbury broke up the no-hit bid and put the Bosox ahead for good when he belted a 3-1 pitch into the right field stands.
The Red Sox outfielder later added a run-scoring single and Mauro Gomez supplied a pair of RBI as Boston claimed the first of a three-game series.
Cook (4-10) limited the Rays to one run on five hits over six innings, walking one and striking out one.
Cobb finished by yielding four runs (three earned) on just two hits over six full frames. The right-hander walked three and fanned four.
Ben Zobrist provided the only RBI for the Rays, who came into the contest four games out of an American League wild card spot.
NBC reportedly holds celebs hostage to Jimmy Fallon's show
Boston schools pull out free condoms over wrapping complaints