Arizona manager Torey Lovullo celebrated his 58th birthday with the victory, which snapped a five-game losing streak for the Diamondbacks
Arizona earned its 26th comeback win of the season.
Ketel Marte ignited the three-run, eighth-inning rally with a leadoff triple against Cardinals reliever JoJo Romero (2-1)
Jake McCarthy then singled up the middle to score Marte to tie the game at 1.
Chris Stratton entered in relief and got Lourdes Gurriel Jr. to ground out before striking out Christian Walker.
After Dominic Canzone walked, Carroll, coming to the plate as a pinch hitter, belted a triple off the wall in right-center field.
Kyle Nelson (5-2) earned the win in relief and Kevin Ginkel earned his third save, working around a single in the ninth inning.
Steven Matz engaged in a pitchers' duel with Arizona's Merrill Kelly, holding the Diamondbacks scoreless through six innings
Matz allowed five hits and one walk while striking out six.
Kelly made his first start since June 24 after being on the 15-day injured list due to a blood clot in his right calf. He allowed one run on four hits in six innings with five strikeouts and two walks.
St. Louis scored its lone run against Kelly in the top of the third inning after Brendan Donovan hit a double with one out.
Paul Goldschmidt followed with a single that moved Donovan to third, and the Cardinals then executed a successful double steal, with Donovan scoring and Goldschmidt advancing to second base. Nolan Arenado did strike out on the play, though
Goldschmidt broke from first and drew a throw from catcher Carson Kelly, at which point Donovan headed for home. Marte's return throw from second base to the plate was not in time.
--Field Level Media