Updated

(SportsNetwork.com) - The Oakland Athletics stared down a painful collapse and came away with a playoff berth on the final day of the season.

Oakland locked down baseball's last spot in the postseason -- the second AL wild card -- with a 4-0 win on the road against Texas on Sunday.

A loss would have put the A's, baseball's best team for much of the season, in a one-game playoff on Monday in Seattle. The Mariners, who were trying to make the playoffs for the first time since 2001, beat the Angels Sunday but ended a game out.

Oakland right-hander Sonny Gray, who lost Game 5 of the AL Divisional Series to Detroit last year, pitched a six-hit shutout against the Rangers on Sunday to get his team back to the postseason.

"This was just as much pressure if not more just knowing that we had to win this game," said Gray. "We had to win that game, too, but this was something different."

The A's, who led MLB with a plus-157 run differential, finished 88-74 after going 22-34 in their last 56 games and will play in Kansas City on Tuesday night.

The Royals made the playoffs for the first time since 1985 and had a chance to force a one-game playoff for the AL Central title, but Detroit won it on the last day with a victory over Minnesota.

The winner of Tuesday's wild-card game will start a divisional series against the AL West-champion Angels on Thursday in Anaheim, the same night the Tigers will face AL East-champ Baltimore on the road to start that set.

In the other race determined on Sunday, the St. Louis Cardinals wrapped up the NL Central crown with a Pittsburgh loss to Cincinnati.

So the Pirates will host the San Francisco Giants in the NL wild-card game on Wednesday with the winner facing the NL East-champion Nationals in Washington on Friday.

The Cardinals will play the NL West-champion Dodgers beginning in Los Angeles on Friday.

The American League Championship Series is scheduled to start Oct. 10 with the NLCS beginning the next day. Game 1 of the World Series is scheduled for Oct. 21 in the ballpark of the AL champions.