The game marked the first time instant replay was available for boundary home run calls, but it wasn't used.
Behind a strong performance from Cole Hamels, Philadelphia had a 4-1 lead heading into the eighth. Hamels had given up just a run and five hits in seven strong innings before the Phillies' bullpen collapsed.
Philadelphia was coming off a tough loss to the Mets on Wednesday night when it also failed to hold an eighth-inning lead. But this one was worse.
Cubs starter Ryan Dempster, who'd pitched out of trouble all game, gave up a leadoff double to Jayson Werth in the sixth, walked Pedro Feliz and then surrendered a go-ahead RBI single to No. 8 hitter Carlos Ruiz. Hamels sacrificed, Jimmy Rollins hit a sacrifice fly and Chase Utley followed with an RBI single, his third hit of the game, to put the Phils up 4-1.
But reliever Ryan Madson gave up three straight hits to start the bottom of the eighth. Pinch-hitter Mike Fontenot homered leading off to make it 4-2, Alfonso Soriano doubled and moved to third on Ryan Theriot's single.
Durbin (5-3) relieved and walked Derrek Lee to load the bases with no outs. Ramirez then hit a 1-0 pitch deep into the seats - Philadelphia center fielder Shane Victorino hardly moved as the ball left the bat - to give the Cubs the lead with his 24th homer.
With the loss, the Phillies dropped a full game behind the idle Mets in the NL East. The Cubs lead Milwaukee by 6½ in the NL Central.
Bob Howry (6-4) pitched the eighth for the win. Kerry Wood gave up a leadoff single to Rollins in the ninth and a long warning track fly ball to Utley before getting his 28th save in 33 chances.
The Cubs tied the game 1-1 in the fifth when Kosuke Fukudome beat out a single behind second and Mark DeRosa drove a 1-2 pitch into the right-field corner for a run-scoring triple.
The Phils got to Dempster for a run in the first but left the bases loaded. Utley doubled, moved on a grounder and following a walk to Ryan Howard and scored on Victorino's single. But after walking Werth to load the bases, Dempster fanned Feliz.
Philadelphia had second and third in the fifth after an Utley single and double by Howard but this time Dempster struck out Victorino.