Nick Castellanos hit a two-run homer in the bottom of the ninth to tie the game, and Manny Machado walked it off on a sacrifice fly in the bottom of the tenth as the San Diego Padres defeated the St. Louis Cardinals 3-2.