The Cubs, who began the day with a 1 1/2-game lead over Milwaukee, hit four homers and withstood a shaky start from Jason Marquis to send the Pirates to their seventh straight loss.
The Brewers, who played Friday night at Atlanta, had 10 games remaining while the Cubs have eight.
Ramirez hit a three-run homer in the first off Paul Maholm. He delivered another three-run shot, his 25th homer of the season, off Franquelis Osoria (0-2) to break a 7-7 tie in the sixth. It came right after Pirates' second baseman Freddy Sanchez dropped a flip on a perfect double-play ball.
With Alfonso Soriano at first and one out, Derrek Lee hit a hard grounder to short, but Sanchez couldn't catch the throw from Matt Kata, that could have led to the side being retired. Instead, Ramirez capitalized on the miscue and put the Cubs ahead.
Two batters later, Geovany Soto hit a two-run homer off John Grabow, and the Cubs had a five-run lead.
Soriano hit his 29th homer leading off the bottom of the first. The Cubs added another run in the seventh when Lee had an RBI single after the Pirates' third error of the game. Ramirez nearly followed with his third homer of the game, flying out to the wall.
Scott Eyre (2-1) pitched the top of the sixth for the win.
With the wind blowing out at 12 to 21 mph on a humid 85-degree day, crazy things were bound to happen at Wrigley Field
- and they did.
By the bottom of the third inning, both starters had been driven out, the game was tied at 7 and the teams had already combined for 19 hits.
Maholm, who entered the game with a 4-0 career record against the Cubs, including 2-0 this season, had been routed in his previous start, giving up 11 hits and 10 runs to the Astros last Sunday in just 2 2-3 innings.
This time he didn't make it that far, going two-plus innings and surrendering 10 hits and seven runs, six earned.