The A’s had a four-run lead in the eighth inning and one-run leads in the ninth and 12th, but the Royals refused to go away on Tuesday night and ended Oakland’s season with a 9-8 victory when Jason Hammel gave up a walk-off single to Salvador Perez in the 12th.