KANSAS CITY, Mo. (AP) — The Kansas City Royals are in the American League Division Series after winning the wildest of Wild Card games.

Salvador Perez hit a walkoff single and the Royals scored twice in the bottom of the 12th to pull out a 9-8 win over the Oakland Athletics in Kansas City. The Royals rallied from deficits of 7-3 and 8-7 before earning the right to face the Los Angeles Angels in the ALDS.

The last comeback occurred after pinch-hitter Alberto Callaspo laced an RBI single for the A's following a walk, a bunt and a wild pitch. Oakland reliever Dan Otero got the first out in the bottom of the 12th before Eric Hosmer tripled and scored on an infield single by Christian Colon.

Colon moved up to second when catcher Derek Norris let a pitchout pop out of his glove, allowing Perez to come up with the winning hit.

Brandon Moss hit a two-run homer and a tiebreaking, three-run blast while the A's were building a 7-3 lead. The Royals scored three times in the eighth and forced extra innings on Nori Aoki's sacrifice fly in the ninth.

The Royals stole seven bases, leading to four runs. Five of those steals came off Derek Norris after Geovany Soto left the game in the third inning, two innings after he suffered a thumb injury during a play at the plate.

Neither starter was very sharp considering their reputations as big-game pitchers. A's hurler Jon Lester surrendered six runs and eight hits over 7 1/3 innings. Royals ace James Shields was reached for four runs and five hits in five frames, including Moss' first-inning blast.

Jason Frasor picked up the victory despite allowing the tiebreaking single in the 12th. Otero was the loser.