The multi-homer game was the 12th of Ramirez's career, establishing a club mark. Dan Uggla and Mike Lowell each had 11. The last time the Miami slugger went deep twice in the same game was July 2, 2011, at Texas.
Both of Ramirez's homers were off Cole Hamels (8-2), who had won eight straight decisions. The left-hander's two losses have been to Miami.
"Hanley is a good hitter. Hanley is one of the best hitters in the game, even though you may not want to believe that," manager Ozzie Guillen said. "I think Hanley has got some credentials."
Now with 144 homers, Ramirez moved past Lowell (143) for second most in club history. Uggla's 154 is the team's record.
Entering the game, Ramirez hadn't homered in 53 at-bats against Hamels. The first homer came on his second at-bat of the game.
"You don't change your approach," Ramirez said of going against a hot pitcher. "You just go up there looking for a good pitch to hit. That's what we've been doing. I think we've shortened our swing down a little bit and tried to get on base."
Heath Bell closed out the ninth for his 11th save in 15 chances. Placido Polanco singled, and there was some dispute in the inning when Freddy Galvis dropped a sacrifice bunt.
First baseman Logan Morrison applied a swipe tag on the speedy Galvis, who was ruled out.
Phillies manager Charlie Manuel argued, which also delayed the situation, making Bell have to stand around near the mound. After the game, the umpires ruled no tag was applied, but Galvis was called out of the base line.
"It was one of those things, he came out because of the call, but he also came out to try to disrupt me," Bell said. "I understand that. I wasn't going to let it affect me. I didn't really want to throw pitches, because I felt good. Charlie wasn't out there for too long, so I thank him for that."
The potential tying run was stranded at second when Jimmy Rollins popped out to shortstop Jose Reyes.
The Marlins overcame a three-run deficit and claimed the lead in the sixth on Ramirez's two-run homer. Omar Infante reached on an infield single, and Ramirez went deep to left field, putting Miami in front, 4-3.
"Like I say, we don't give up," Ramirez said. "Everybody wants to win. Everybody is on the same page. Ozzie, he set the mood in Spring Training. We're just following him and the words he said in the meeting."
In the seventh, the Marlins made it a two-run margin on Reyes' two-out RBI double, which extended his hitting streak to 13 games.
Nolasco got into trouble in the eighth inning, yielding a leadoff triple to Jimmy Rollins and a walk to Juan Pierre. Steve Cishek replaced Nolasco, and after Pierre stole second, Hunter Pence's sacrifice fly to right made it a one-run game. Pierre advanced to third on the throw home. Cishek struck out Carlos Ruiz, and after Shane Victorino walked, Ty Wigginton struck out swinging through a full-count fastball.
Miami chipped back from three runs down by scoring twice in the fourth inning.
Ramirez got the inning in motion with his first home run. The liner over the wall in left-center came on Hamels' first pitch of the frame. It was reviewed because a fan reached over the railing and caught it in his glove.
The umpires left the field, and replays showed the ball had the distance and that the fan extended over the railing. So the homer was upheld.
"I thought it was a homer right off the bat," Hamels said. "If it wasn't a homer, I was going to be more lucky than anything, because I threw the pitch. He guessed right and hit it hard. When that happens, they deserve the home run. But you have to come back and get the next guy out and I wasn't able to do that. Then I gave up another run in that inning."
The last time the Marlins were involved in a review was on Sept. 4, 2011, against the Phillies at Sun Life Stadium. In that game, Pence had a double reversed to an out due to fan interference.
The Phillies built a 3-0 lead, scoring one run in each of the first three innings.
Ruiz had an RBI groundout in the first, bringing home Pierre. In the second, Rollins had a run-scoring single, and Pence homered to lead off the third.
"It's tough on your team when you give up three straight runs in the first three innings, knowing [Hamels] is so good, 8-1 and stuff, and just rolling," Nolasco said. "I knew, even though I didn't catch a couple of breaks, that I just tried to keep making good pitches and maybe we could scratch something together. Hanley did a great job hitting those balls out against them, and we just grinded out at-bats against them and came out on top."