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 (ky-AS'-poh) 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 (NOHR'-ee ah-OH'-keez) sacrifice fly.

The Royals stole six 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.

ANAHEIM, Calif. (AP) — Angels outfielder Josh Hamilton says he's feeling better and is ready for the playoffs this week. The former AL MVP missed 21 of the Angels' final 22 regular-season games because of shoulder and other upper-body injuries. Angels pitcher Matt Shoemaker also said he's feeling fine after being sidelined the last two weeks because of an oblique strain on his left side.

UNDATED (AP) — Max Scherzer (SHUR'-zur) will be on the mound when Detroit opens its AL Division Series against the Orioles in Baltimore. Scherzer went 18-5 this season with a 3.15 ERA.

Manager Brad Ausmus will go with Justin Verlander in the second game and David Price in Game 3 when the series shifts to Detroit.

Orioles manager Buck Showalter will start Chris Tillman in Thursday's opener. Wei-Yin Chen (way yihn-chehn) starts Game 2 for the Birds, followed by Miguel Gonzalez at Comerica Park.

NEW YORK (AP) — Yankees outfielder Carlos Beltran has undergone elbow surgery to remove a bone spur and loose pieces that limited his throwing ability for most of the 2014 season. The team says Beltran can start throwing and hitting in about six weeks and can play baseball in approximately 12 weeks.