In a moment that retired Boston slugger David Ortiz often flourished in, with the Red Sox down two runs in the late innings, Ramirez delivered the game-tying blow.
Ramirez's two-run double to center field with one out and the bases loaded in the eighth erased the deficit, and Xander Bogaerts brought him home shortly thereafter as the Red Sox rallied past the Pittsburgh Pirates 4-3 at Fenway Park.
"When they choose to pitch to Hanley, he puts a beautiful swing on a pitch to give us extra bases when we needed it most," Boston manager John Farrell said.
Ramirez appeared to give Boston (5-4) the lead after his two-bagger cleared the bases.
However, the Pirates challenged home plate umpire Gabe Morales' ruling that trailing runner Mookie Betts was safe at the plate, and the call was overturned.
Betts was merely a few feet behind Andrew Benintendi, who held up just past second base to make sure Pirates center fielder Starling Marte didn't make the catch, as he attempted to score from first.
But Ramirez took third on the throw and scored on Bogaerts' opposite-field single to right, making the close call an afterthought.
"It's a bang-bang play with Mookie, but fortunately Bogey makes it all go away," Farrell said.
Thursday's game was a make-up after last Thursday's series finale was rained out.
Pittsburgh (3-6) lost 5-3 on Opening Day last Monday in Boston and was blanked 3-0 in the second game Wednesday. The Pirates entered the make-up game coming off a three-game sweep against the Cincinnati Reds.
"We play 162 in the regular season. I've been around long enough to know it doesn't matter right now," Pirates star Andrew McCutchen said. "You're going to battle, you're going to win, you're going to lose. And that's what it's all about."
McCutchen, a combined 0-for-9 with three strikeouts in the first two games at Fenway last week, launched a two-run homer. It the 176th of his career, tying Barry Bonds for the fourth-most in Pirates history.
Marco Hernandez also had an RBI for Boston. Mitch Moreland doubled in his Red Sox-record seventh straight game and leads the majors with eight two-baggers.
"It's not something I'm really concentrating on," Moreland said. "When I go to the plate, I'm trying to keep it as simple as possible, get a good pitch to hit and try to get the barrel to it. If they go for doubles, I'll take them all day long."
Juan Nicasio (0-2) gave up the winning single to Bogaerts after Daniel Hudson coughed up the tying runs to Ramirez.
Red Sox starter Eduardo Rodriguez was tagged for three runs (two earned) on four hits and four walks while striking out eight in a 5 1/3-inning no-decision.
Pirates starter Chad Kuhl held the Red Sox to one run on five hits and struck out six over 6 1/3 innings.
"Chad pitched a fantastic game," Pittsburgh skipper Clint Hurdle said. "To hold that offense in check, to pitch into the seventh, no walks, six strikeouts, the fastball command was excellent."
Pittsburgh enjoyed a quick start this time around after failing to advance a runner past first base in last Wednesday's game at Fenway.
McCutchen blasted a first-pitch fastball from Rodriguez off the AAA sign on the Green Monster in left field following a walk to Jordy Mercer, putting the Pirates up 2-0 in the first.
Boston got a run back in the second on Hernandez's one-out double off the wall in left that plated Moreland from second.
Gregory Polanco stole third and scrambled home after Red Sox catcher Christian Vazquez's throw sailed into left field with two down in the sixth, restoring Pittsburgh's two-run lead.
NOTES: Pittsburgh RF Andrew McCutchen's homer was the first ever for a Pirates hitter at Fenway Park. ... Boston activated LHP Robbie Ross Jr. from the 10-day disabled list and optioned RHP Ben Taylor to Triple-A Pawtucket. Ross went on the DL last Thursday (retroactive to April 3) with influenza. ... Red Sox LHP David Price (left elbow strain) threw from 90 feet Thursday and will throw a 45-pitch bullpen Saturday. RHP Tyler Thornburg (right shoulder impingement) also threw from 90 feet and INF Josh Rutledge (left hamstring strain) took ground balls before the game. ... Pittsburgh visits the Chicago Cubs while Boston hosts the Tampa Bay Rays on Friday. Pirates RHP Gerrit Cole (0-1, 6.55 ERA) faces Cubs RHP Kyle Hendricks (1-0, 6.00 ERA) and Red Sox RHP Rick Porcello (1-0, 4.38 ERA) opposes Rays RHP Chris Archer (1-0, 2.45 ERA).