The Padres handed St. Louis starter Kyle Lohse (14-3) his first loss since June 15.
Yasmani Grandal singled in the go-ahead run in the sixth inning to make a winner out of Clayton Richard (13-12), who allowed just three hits over seven frames to capture his fourth consecutive decision.
One of the hits Richard gave up was a two-run homer by Matt Carpenter in the top of the sixth that briefly brought about a 2-2 tie.
Gregerson came on in the ninth to protect the one-run lead and gave up a leadoff double to Allen Craig.
Craig moved to third on a sacrifice by Yadier Molina and he had to stay there when David Freese hit a grounder to third. After Carlos Beltran walked, Gregerson got Skip Schumaker on a ground ball to first that ended the game. It was Gregerson's seventh save and second in as many nights.
Lohse allowed three runs, although just two of them were earned on five hits in six innings. He struck out eight. Lohse had started 15 straight games without a loss.