Updated

Improbably, the Pittsburgh Pirates' offense had a bigger inning than it has had since May. Unlike he had all season, James McDonald made it through seven innings.

But based on the way the past 10 days have gone for the Pirates, the most predictable outcome Thursday night was that neither mattered. They still resulted in another loss.

Carlos Pena hit one of Chicago's three home runs and walked with the bases loaded during a three-run eighth-inning rally as the Cubs won their season-high fifth straight, a 7-6 victory over Pittsburgh on Thursday night.

The Pirates — in first place in the NL Central 10 days ago — have lost a season-high seven straight and nine of 10.

"Through the course of the season, things like this are going to happen, and they happen to everybody," said reliever Joe Beimel, who walked Pena to force in the tying run. "It's how you rebound after a streak like this. We're very capable of going on a streak where we win 10, 11 in a row."

That might sound improbable — but don't tell that to the Cubs. They have the second-worst record in the National League but completed a 10-game road trip on a season-high five-game winning streak.

The hot stretch followed losses in each of the first five games away from home.

"Go figure," manager Mike Quade said. "It'll drive you nuts sometimes if you try to figure it out. That's why you keep playing."

Pena, Geovany Soto and Blake DeWitt homered to give Chicago 10 in the four-game sweep, the Cubs' first in Pittsburgh in 52 years. Chicago is on its longest winning streak since Sept. 13-19, 2010.

The Cubs hit only two home runs in those first five games of the trip but have 11 during their winning streak.

"They have an offense that can hit, and they've got some guys in there who've got some history of hitting home runs," Pirates manager Clint Hurdle said. "But we did miss a lot of our locations and elevated a lot of pitches."

McDonald not only made it through seven innings for the first time since Sept. 13, he had his first three career RBIs during a six-run fourth.

He was in line for the win until Daniel McCutchen relieved him in the eighth and did not retire any of the three batters he faced. All of them scored.

Trailing 6-4 heading into the eighth, the Cubs' Reed Johnson and Starlin Castro began with singles. McCutchen (3-3) hit Darwin Barney with a pitch to load the bases.

"And the inning just got more complicated from there," Hurdle said.

It sure did for Pittsburgh, which was on its fourth reliever of the inning before an out was recorded.

Aramis Ramirez followed with an RBI single off Jason Grilli, and then Beimel walked Pena before Jose Veras induced a sacrifice fly from Marlon Byrd.

It was the Cubs' eighth win this season when they entered the eighth inning trailing.

Jeff Samardzija (6-4) pitched a scoreless seventh to earn the win, and Carlos Marmol worked a perfect ninth for his fourth save in the past five days and 23rd of the season.

Soto led off the third by homering for the second time in three games and 11th time this season. With nobody on and two outs in the fourth, Pena took the first pitch from McDonald into the shrubbery beyond the wall in straightaway center.

Byrd followed with a single — his 1,000th career hit — and he scored when DeWitt hit a towering shot to right, his third.

"It's been a tough year," Pena said, "but we're starting to play better now. We're swinging the bats well and giving our pitchers some confidence because it's easier for them when they have a big lead."

It hasn't appeared easier for Cubs starter Rodrigo Lopez. He had been given a 5-0 lead in his most recent outing Saturday in St. Louis — but he wasn't able to get out of the fifth inning and ended up taking the loss. A similar situation appeared to be playing out Thursday, as Lopez was lifted after Pittsburgh's fourth-inning outburst erased a four-run Cubs lead.

The Pirates hadn't scored more than six runs in a nine-inning game since July 10 — but they got that many on six hits in the fourth, highlighted by McDonald's liner into the left-center field gap for a double that cleared the bases and gave Pittsburgh its first lead. Andrew McCutchen followed with a double, scoring McDonald.

Earlier in the inning, Ryan Ludwick's first hit in 10 at-bats with Pittsburgh drove in the Pirates' first run. Ludwick later scored on a fielder's choice by Xavier Paul.

Notes: Andrew McCutchen has reached safely in each of his past 28 games against Chicago and 31 of his past 32 home games overall. ... Pittsburgh RHP Chris Leroux (left calf) began a rehabilitation assignment for Triple-A Indianapolis. ... Ludwick is 11 for 30 (.367) in his career against San Diego's Aaron Harang, whom Pittsburgh will face to begin a three-game weekend series on Friday. Ludwick is a .301 hitter lifetime against the Padres, who traded him to the Pirates on Sunday. ... Friday Cubs starter Ryan Dempster has won three of his past five starts but has lost his past two decisions against Cincinnati.