St. Louis has won two in a row against the Marlins after dropping nine of 10 overall.
Miami lost its third straight.
Goldschmidt, who had a tying RBI single in the sixth, led off the ninth and fell behind 1-2 in the count before he drilled a 98 mph fastball from Yimi Garcia (3-5) to right-center field for his sixth career walk-off home run. The previous one also came against the Marlins in June 2019 to give St. Louis a 2-1 victory in 11 innings.
Alex Reyes (4-2) worked a scoreless ninth for the win.
Goldschmidt tied the game with a two-out, two-strike hit in the sixth. Pinch-hitter Jose Rondon began the rally with a one-out single.
Miami starter Trevor Rogers allowed one run and three hits over six innings. He struck out six and walked one. Rogers has held opponents to one run or none in eight of his 14 starts this season.
St. Louis starter Kwang Hyun Kim also gave up one run and three hits in six innings. He struck out six and walked five.