Beckett (2-1) beat the Yankees for the second time this year, giving up three runs on six hits while striking out five.
Ramirez had three hits with three RBI and J.D. Drew chipped in a two-run double. Boston won for the fifth time in six games and bounced back from a 15-9 loss to the Yankees Wednesday.
Ramirez moved past Lou Gehrig and Fred McGriff into 24th place on the all-time home run list with 495. He has 55 homers against the Yankees, the third-most ever against them behind Jimmie Foxx (70) and Ted Williams (62).
The loss went to Mike Mussina (1-3), who surrendered five runs on seven hits in just three innings.
Boston scored the game's first seven runs and broke the Yankees' three-game winning streak.
Ramirez homered to lead off the second and contributed a two-run shot in a four-run third.