CHICAGO -- It became obvious early that the task the Pirates faced Tuesday night was not going to be an easy one.
As it turned out, Russell Martin's eighth-inning sacrifice fly scored Starling Marte to lift the Pirates to a 7-6 win against the Chicago Cubs at Wrigley Field. It was the third Pirates lead of the night, but the other two vanished.
Cubs relievers Pedro Strop and James Russell loaded the bases with three walks in the eighth, setting the stage for Martin.
"We just kept playing," said Pirates manager Clint Hurdle. "It's not about what's not happening, it's about what we've got to do next. It was a fist fight off the mound for us for most of the night."
Starlin Castro homered twice against Pirates starter Charlie Morton, and it was about to be the Emilio Bonifacio show before Martin's sacrifice fly and one shutdown inning each from relievers Mark Melancon and Jason Grilli.
Bonifacio, the Cubs leadoff hitter, wreaked more havoc against the Pirates by scoring the tying run in the seventh inning to cap his 3-for-5 night.
Bonifacio, an almost unbelievable 14 for 21 against the Pirates already this season, singled to open the seventh, took second on a grounder, stole third, then scored on Anthony Rizzo's single to tie the game, 6-6.
"We know what we need to do. We haven't been able to do it. He wouldn't be in Chicago right now if he'd done this his whole career," said Hurdle. "We're just not in a good place with the ball. We're not getting the ball in the spots we need to. Give him credit. He's barreling up a lot of balls from both sides of the plate. Giving them a lot of good at-bats."
Rizzo's single was off reliever Tony Watson, and broke Watson's 221/3 scoreless inning streak dating to last season.
Melancon sat the Cubs down 1-2-3 in a very efficient eighth and closer Grilli earned the save in the ninth with a swinging strikeout, Bonifacio's line-drive out to short and a grounder to third.
The Pirates seized a 4-0 lead in the first. Marte doubled on the first pitch of the night.
"I was ready for the first pitch," said Marte.
But Morton did not have his best start, giving up five earned runs in six innings, including two homers to Castro. In all, Morton gave up eight hits, walked one and struck out five.
It was a stark contrast from his previous start at Wrigley on the September night the Pirates clinched a postseason berth for the first time in more than two decades.
"It was two bad pitches," said Morton, referring to Castro's homers. "I threw a four-seamer trying to go down and away, [and] the ball ran up and in. He got under it and hammered it. That curveball was just terrible.
"The two pitches they scored four of those runs were just terrible pitches."
Cubs starter Edwin Jackson gave up six earned runs of his own.
The Pirates got to Jackson early, taking a 4-0 lead in the first on four hits, a walk, a hit-by-pitch and sacrifice fly. The Cubs threatened in the bottom of the inning with a walk and error by Marte, who ran down a flare shot to shallow left but dropped the ball.
Morton escaped that jam with a strikeout.
The Cubs scratched out a run in the second, but tied the game, 4-4, in the third, when Castro sent a 1-2 pitch over the left-field wall with two men on.
Andrew McCutchen singled in Marte in the fifth to make it a 5-4 lead and Travis Ishikawa hit a sixth-inning triple that scored Martin to give the Pirates a 6-4 lead.
Castro took Morton deep again in the sixth, but Morton got out of the inning with the Pirates hanging onto a 6-5 lead.
NOTES — Tuesday was the first of 38 night games that will be played at Wrigley Field this season. …Catcher Chris Stewart (knee) caught five innings for Class A Bradenton on Tuesday, went 0 for 2 and threw out a runner attempting to steal.
Jenn Menendez: email@example.com and Twitter: @JennMenendez