The Padres trailed 2-1 when Carlos Quentin's solo shot in the fourth inning forged a tie game.
Alonso then put San Diego ahead to stay in the next frame when he smashed a 1-2 pitch from Ian Kennedy (11-11) over the right-field fence for a solo shot.
Chase Headley added a bases-empty clout and a sacrifice fly for the Padres, who clinched their three-game series with their sixth straight victory.
Richard (11-12) won for the fourth time in five starts, surrendering three runs on seven hits in an eight-inning effort. He walked two and struck out four.
Kennedy ended up yielding six runs on four hits, lasting 5 1/3 frames.
Justin Upton delivered a two-run, inside-the-park homer for Arizona.