CHICAGO -- The Pittsburgh Pirates had gone 21 years between playoff appearances so it did not matter that they had to wait a little while after their 2-1 victory over the Chicago Cubs on Monday to clinch a playoff spot.
The Pirates' magic number fell to one with the victory, and they clinched a berth in the postseason when the Cardinals beat the Nationals 4-3 a little later.
The Nationals' loss assured a playoff spot for both the Reds and Pirates, and it is Pittsburgh's first postseason berth since 1992.
Starling Marte broke a 1-1 tie with a solo home run in the ninth off Cubs reliever Kevin Gregg for the Pirates go-ahead run.
Right-handed reliever Mark Melancon (3-2) pitched the eighth and got the win.
Pittsburgh right-hander Jason Grilli worked the ninth for his 32nd save. But when Ryan Sweeney singled to right-center, the Pirates needed a combination of accurate throws to prevent the tying run from scoring. Center fielder Andrew McCutchen picked up the ball and threw to first baseman Justin Morneau, who relayed the ball to catcher Russell Martin to get Chicago's Nate Schierholtz at the plate.
It was the second straight loss in relief for Gregg (2-6), who also struck out three in his one inning of work.
Neil Walker's first-inning solo home run gave the Pirates a lead they would maintain until the eighth.
Pittsburgh starter Charlie Morton worked seven scoreless innings but had to settle for his third straight no-decision. He yielded three hits, walked one and struck out five.
The Cubs tied the game in the in the eighth as Brian Bogusevic singled to center to open the inning against Melancon.
Bogusevic reached second on Darwin Barney's infield grounder and moved to third on a wild pitch. Pinch-hitter Donnie Murphy brought him home when he lined a single to left.
Chicago starter Jeff Samardzija pitched six innings and allowed just one run on five hits, while striking out seven and walking four.
His last win came on Aug. 24, a 3-2 victory at San Diego. Since then he's had a loss and four no-decisions.
Walker's home run was his 14th of the season and came on a 1-1 pitch from Samardzija.
Martin reached third with one out in the second, but he was tagged out at the plate on Morton's bunt.
The Cubs had runners at second and third in the bottom of the inning following Bogusevic's double down the first base line, but Barney lined out to left to end the threat.
Pittsburgh had lost five of seven coming into the series and split its previous six games at Wrigley Field.
The Cubs and Pirates play twice more before beginning season-ending series. Chicago wraps up with three weekend games in St. Louis, while Pittsburgh plays at Cincinnati, its likely wild-card playoff opponent.
NOTES: The Pirates last reached the playoffs with a 96-win season in 1992, when they lost in the National League Championship Series to the Braves. After that came 20 consecutive losing years until 2013. ... Pittsburgh has a 40-36 road record, the franchise's best since posting a 43-38 mark in 1992. ... Pittsburgh RHP Gerrit Cole (9-7, 3.23 ERA) goes against Chicago LHP Chris Rusin (2-5, 3.52) on Tuesday. ... Sweeney played in his 600th major league game. ... Cubs RHP Carlos Villanueva began the night 5-0 with a 1.17 ERA in 12 relief appearances since Aug. 21. He held opponents to a .196 average while walking just three and striking out 16 in that span.