The Pittsburgh Pirates are going to the playoffs for the first time in 21 years, clinching at least a National League wild-card spot Monday night with a 2-1 victory over the Cubs in Chicago and the Washington Nationals’ loss to the St. Louis Cardinals.

It will be Pittsburgh’s first trip to the postseason since a team led by Barry Bonds and Jim Leyland won three straight N.L. East titles from 1990 to ’92. Bonds then left for San Francisco as a free agent, and the small-budget Pirates piled up 20 consecutive losing records, the longest streak in the four major North American professional sports.

On Monday, Starling Marte hit a tiebreaking homer in the ninth inning, and the Pirates threw out a runner at the plate for the final out.

CARDINALS 4, NATIONALS 3 Carlos Beltran homered, Adam Wainwright earned his 18th win and host St. Louis topped Washington, eliminating the Nationals from playoff contention. Looking for their first N.L. Central title since 2009, the Cardinals maintained a two-game lead over Cincinnati and Pittsburgh and reduced their magic number to four.