Jason Motte (4-4) struck out Miguel Montero in the ninth but then served up Goldschmidt's 18th home run and Young's 12th.
J.J. Putz set the Cardinals down in order in the bottom of the ninth for his 23rd save. David Hernandez (2-2) pitched a scoreless eighth to get the win for Arizona, which had lost seven straight to St. Louis.
Diamondbacks starter Trevor Cahill went six innings, allowing one run on five hits and a walk over six innings.
Lohse, who came into the contest with a personal six-game winning streak, shut out Arizona on four hits with three walks and five strikeouts over 6 2/3 innings.
Swim Week Miami Beach 2014 [PHOTOS]