Randy Wells (7-4) worked six innings for the win, scattering seven hits and one run.
"I've faced the Pirates a lot. Those guys know what I'm trying to do so I tried to make adjustments and keep them off balance," Wells said.
Neil Walker hit a two-run homer for the Pirates, who have lost six of their last eight. Charlie Morton (9-9) lasted just 4 1/3 innings in defeat, charged for seven hits and four runs -- three earned -- and tying a season high by issuing five walks.
"It's frustrating when you're struggling," said Morton.
Chicago provided itself some breathing room in the fifth. Aramis Ramirez singled, Pena walked and LaHair reached on an error to load the bases with none out. Byrd's fly to center made it 3-1, then after Darwin Barney was hit, Morton exited for Tony Watson. Koyie Hill's grounder to first scored Pena for a three-run margin.
Ramirez drew a two-out walk in the home sixth, stole second and scored two batters later on a LaHair base hit.
Lee's one-out single in the eighth preceded Walker's two-run shot to bring the Bucs within 5-3, but Pena walked with two down in the home half and scored on Byrd's base hit for a three-run cushion once more.
Alex Presley began the game with a single and later came around to score on Lee's two-out base hit.
In the third, Tony Campana singled and stole second, Ramirez walked and Pena's fielder's choice grounder pushed across Chicago's first run of the game.
The Cubs went up 2-1 in the next frame when Castro's infield single plated Hill.
Wells has given up just 11 hits and two earned runs over 21 2/3 innings in his last three starts, all wins. He hasn't lost since July 28...Morton also walked five batters in consecutive starts April 4 and 9, then on May 1 and finally on July 24...The season series ended in an 8-8 split, with Pittsburgh winning six of nine in Chicago...Both clubs are back in action on Monday, as the Cubs host the Reds and the Pirates welcome Houston.