CHICAGO (AP) Gerrit Cole outpitched Jon Lester as the Pittsburgh Pirates hung on for their seventh straight win, beating Chicago 3-2 Friday to delay the Cubs' playoff celebration.

Pittsburgh increased its lead for the NL's top wild card to 4 1/2 games over the Cubs, who would have secured their first postseason appearance since 2008 with a victory. Chicago would clinch with a loss by San Francisco to Oakland on Friday night.

Cole (18-8) and Lester (10-12) each lasted seven innings, and Mark Melancon held off a rally attempt in the ninth for his major league-leading 51st save in 53 chances.

More from FoxSports

Chris Denorfia led off the ninth with a double and scored on Starlin Castro's one-out triple to right as the Cubs closed within a run and excited the crowd of 40,432..

Melancon then struck out Jorge Soler and Javier Baez on knuckle curves in the dirt.

Cole gave up two runs and five hits, struck out eight and walked two while improving to 7-1 in nine starts against Chicago.

He also drove in the game's first run with a single in the third.

Michael Morse put Pittsburgh ahead 2-1 with an RBI single off Lester in the seventh. The Pirates added a run in the eighth against Pedro Strop when Jordy Mercer reached on a wild pitch as he struck out leading off and scored from third on a grounder by Starling Marte.

Lester allowed two runs and five hits.

Kris Bryant had two hits and scored, but Chicago came up short after winning seven of nine.

The Cubs had runners on first and second in the eighth, but Tony Watson struck out Anthony Rizzo to end the threat.

Cole gave the Pirates a 1-0 lead in the third with a single past a diving shortstop Addison Russell after Jordy Mercer doubled.

The Cubs tied it in the fourth when Bryant led off with a single and scored from third on a force by Addison Russell.

It stayed that way until the seventh, when former Cub Aramis Ramirez led off with a double and scored on Morse's one-out single. Morse, who was running on the pitch, then got doubled off on Josh Harrison's pop fly to first to end the inning.

TRAINER'S ROOM

Pirates: RF Gregory Polanco (knee) and 3B Ramirez (groin) were back in the lineup after being held out Thursday against the Colorado Rockies.

UP NEXT

Pirates: LHP Francisco Liriano (11-7, 3.41 ERA), coming off a win over Clayton Kershaw and the Los Angeles Dodgers, looks to stay on a roll for Pittsburgh. He is 7-1 in his past 15 starts, with the Pirates winning all but one of those games.

Cubs: With a 5.77 ERA over his last 11 starts, RHP Jason Hammel (9-6, 3.79) looks to break out of his slump.