After getting shut down by Giants starter Matt Cain, the Cubs struck quickly against his replacement and held off a ninth-inning rally to send the Giants to their fifth-straight loss.
Ryan Theriot led off the bottom of the eighth with a single off Tyler Walker and Mike Fontenot sacrificed him to second. After Walker (3-5) intentionally walked Derrek Lee, Ramirez launched the first pitch just inside the foul pole in left for his 17th home run, sending the packed crowd into a frenzy.
Bob Howry (3-2) pitched a perfect eighth to get the win. Kerry Wood pitched the ninth for his 24th save.
The Giants have scored four runs total in the last four games, and barely avoided being shut out for the third time in those four games.
Ray Durham led off the ninth with a double after Mark DeRosa hesitated on a flyball to left. Wood then walked Eugenio Velez and Bengie Molina drove in Durham with a single and sent Velez to third.
Emmanuel Burriss, running for Molina, stole second as Wood struck out Aaron Rowand. John Bowker flied out to right, but Kosuke Fukudome, who didn't start the game, made a strong throw to hold the speedy Velez at third. Wood then got Rich Aurilia to ground out to first to end the game.
Cubs pitcher Jason Marquis had a no-hitter going into the fifth until John Bowker led off with a single that bounced off Marquis' leg. Marquis was examined by the trainer but stayed in the game.
Marquis gave up three hits and two walks, striking out four, in seven innings.