PHOENIX (AP) -- J.D. Martinez lined a two-out RBI single to deep left field with the bases loaded in the ninth inning, and the Arizona Diamondbacks beat the Miami Marlins 3-2 on Sunday to clinch the top wild card in the National League.
The Diamondbacks, who won only 69 games a year ago but are 90-66 this season, were already assured a playoff berth earlier in the day when St. Louis lost at Pittsburgh, and Milwaukee was beaten at home by the Chicago Cubs.
The comeback victory over Miami ensured Arizona will host the NL wild-card game Oct. 4.
Fernando Rodney (5-4) pitched a perfect inning for the win.
A throwing error by reliever Justin Nicolino (2-3) on Kristopher Negron's sacrifice bunt helped load the bases with no outs in the Arizona ninth. Ketel Marte and Paul Goldschmidt each hit into a forceout at home. That brought up Martinez, who has been spectacular since he was acquired from Detroit in July. He sent Javy Guerra's pitch on a line shot over the head of left fielder Marcell Ozuna to win it.
Giancarlo Stanton and Brian Anderson each doubled in a run for the Marlins.
Chris Herrmann homered for the Diamondbacks
Arizona tied it 2-all when Goldschmidt led off the seventh with a single, went to second on Ozuna's error and scored on Daniel Descalso's single.
Miami starter Dan Straily gave up one run on four hits in six innings, striking out nine and walking three. Diamondbacks counterpart Patrick Corbin allowed two runs and five hits in 6 2/3 innings.
The Diamondbacks learned they had clinched a postseason spot halfway through the fourth inning with an announcement on the big message board that was followed by a roar from the crowd. In the Arizona dugout, there were hugs and high-fives, and players even came out briefly and clapped hands and cheered the fans.
It's the sixth time Arizona has advanced to the postseason in its 20-year history. The other years were 1999, 2001 (World Series champions), 2002, 2007 and 2011.
Plate umpire Jeff Kellogg was hit in the head inadvertently by Marte's bat. After one more batter to lead off the eighth, Kellogg left the game was replaced at home by first base ump James Hoye.
Diamondbacks: Manager Torey Lovullo said an X-ray on Friday revealed the fracture in INF Chris Owings' middle finger is not completely healed. The earliest possible return for Owings would be the NL Division Series. … C Jeff Mathis (broken hand) has been cleared for more baseball activity and hopes he can play in the final series of the regular season at Kansas City.
Marlins: RHP Odrisamer Despaigne (0-3, 4.37 ERA) starts Monday night at Colorado against RHP Tyler Chatwood (8-13, 4.56).
Diamondbacks: Arizona continues its final regular-season homestand Monday night when RHP Zack Godley (8-8, 3.20 ERA) pitches against Giants RHP Johnny Cueto (7-8, 4.49).