BOSTON -- Alex Rodriguez didn't exactly go out with a bang, but he produced a key run in his final game at Fenway Park as a member of the New York Yankees on Thursday night.

Rodriguez was 0-for-4 with a strikeout, but his dribbler to the mound in his final at-bat drove in a run to cap a three-run Yankees eighth inning. New York came from behind to post a 4-2 win over the Boston Red Sox.

"Kind of a funny hit at the end," Rodriguez said. "Not how I pictured it when I woke up this morning."

Rodriguez, batting cleanup in his final road start, was vigorously booed as he stepped to the plate for the first time in the second inning.

It was a fitting send-off in the eyes of the 41-year-old slugger, who will be released after New York's game against the Tampa Bay Rays at Yankee Stadium on Friday.

"They're exactly what they've meant for a long time," Rodriguez said about the boos. "They're passionate fans. They love their team."

"Just like in the '80s when Celtics-Lakers was good for (basketball), Red Sox-Yankees is also good for baseball."

Rodriguez proceeded to hit a light popout to second following a six-pitch at-bat in the second.

Prior to Rodriguez's RBI groundout in the eighth, former Red Sox center fielder Jacoby Ellsbury hit a decisive two-run, line-drive double to left.

Red Sox rookie left fielder Andrew Benintendi misplayed what looked like a catchable ball, allowing it to roll to the wall.

The play was originally ruled a sacrifice fly for Ellsbury and a run-scoring error on Benintendi, but the decision was changed after the game.

"It went in the lights, but that's no excuse," Benintendi said. "I should have caught it."

Austin Romine added a solo home run, his fourth of the year for New York, which won two of three games in Boston and improved to 6-4 in August.

Yankees starter Michael Pineda allowed two runs on eight hits and two walks with three strikeouts over six innings.

Luis Cessa (2-0) earned the win with two scoreless innings, and Dellin Betances survived a rocky ninth for his third save.

Despite a trade-deadline selloff, the Yankees (58-56) are now just 6 1/2 games behind the American League East-leading Toronto Blue Jays and 3 1/2 games out in the AL wild-card race.

"I've been preaching it, we're fighting," Yankees manager Joe Girardi said. "We're fighting, we're fighting, and we're going to continue to fight."

Hanley Ramirez drove in both runs for Boston, which holds a half-game lead on the Detroit Tigers for the second AL wild card.

The Red Sox (61-52) lost for the fourth time in five games and dropped below 10 games over .500 for the first time since July 8. They trail the Blue Jays by three games in the AL East.

Red Sox starter Eduardo Rodriguez lasted seven innings, giving up a run on three hits and a walk with six strikeouts.

Brad Ziegler (0-3) surrendered all three runs in the eighth.

"I felt like I made a couple pretty good pitches," Ziegler said. "The one Ellsbury hit wasn't even a strike."

Sandy Leon's leadoff double and Benintendi's walk put runners on the corners for Dustin Pedroia with one out in the Boston ninth. However, Pedroia and Xander Bogaerts both struck out.

Ramirez was shaken up after colliding with Gary Sanchez at first base during Sanchez's eighth-inning single.

Sanchez sent a grounder to a shifted Pedroia, playing over at shortstop. Pedroia made a sliding stop but fired an off-target throw to Ramirez at first.

While he was backing up to make the play, Ramirez was bowled over by Sanchez at the bag. Ramirez stayed in the game after being checked out.

Ramirez snapped an 0-for-16 spell with an RBI single in the first, collecting his first hit since tripping down the dugout stairs on Aug. 2 at Seattle.

Romine tied it with his homer in the third, crushing a 1-0 slider from Eduardo Rodriguez over the Green Monster in left field.

Ramirez gave the Red Sox another lead in the fifth, ripping a two-out, RBI double into the right-center gap.

NOTES: Boston DH David Ortiz was in the lineup after fouling a ball off his right shin and leaving Wednesday's game. RF Mookie Betts, who also departed Wednesday with right calf tightness, did not play. Brock Holt started in right. ... New York RHP Nathan Eovaldi underwent an MRI exam Thursday and will seek a second opinion after leaving Wednesday's start with right elbow discomfort. ... Yankees RHP Luis Cessa was recalled from Triple-A Scranton/Wilkes-Barre, and RHP Ben Heller had his contract selected from Scranton/Wilkes-Barre. RHP Nick Goody and INF/OF Rob Refsnyder were optioned to the minors. ... Red Sox LHP Roenis Elias was recalled from Triple-A Pawtucket and OF Bryce Brentz was optioned to Pawtucket. ... Yankees DH Alex Rodriguez asked manager Joe Girardi about playing third base again before he is released Friday. "We thought about it, but he hasn't done any work," Girardi said. ... Yankees LHP CC Sabathia (6-9, 4.18 ERA) opposes Rays RHP Chris Archer (6-15, 4.26 ERA) and Diamondbacks LHP Patrick Corbin (4-11, 5.37 ERA) counters Red Sox LHP David Price (9-8, 4.34 ERA) on Friday.