Lourdes Gurriel Jr. singled and Gabriel Moreno walked to lead off the decisive eighth. With two outs, Carroll sent a sinking liner to right that appeared to be caught by Seiya Suzuki.
Carroll was ruled out, but Arizona challenged the play, believing Suzuki had trapped the ball. The call was overturned, and umpires awarded Gurriel home after deeming that he would have scored on the play.
That would be the only run the Diamondbacks (74-68) needed to pull within two games of Chicago (76-66) for the second National League wild-card spot.
Gallen (15-7) allowed just three hits while striking out nine. He walked one while pitching his second career shutout.
Carroll went 2-for-3 with a walk and three stolen bases for Arizona, which has taken the first two games of the four-game series.
Cubs starter Jameson Taillon gave up just one hit over six innings, walking one and striking out nine. He took a no-hitter into the sixth.
Jose Cuas (3-1), who allowed Gurriel and Moreno to reach in the eighth, took the loss.
Suzuki had two of Chicago's three hits.
Arizona seemed poised to strike right out of the gate when Carroll walked to open the game, stole second and advanced to third on catcher Miguel Amaya's errant throw.
But Taillon struck out Ketel Marte, Tommy Pham and Christian Walker to snuff the threat, beginning a stretch in which he retired 17 consecutive batters.
Carroll broke the stalemate, though, lining a single to left with two outs in the sixth. He once again stole second and moved to third when Amaya's throw skipped into center field, but he was left stranded when Marte grounded out.
Gallen was equally as impressive, as he was perfect until hitting Nico Hoerner with one out in the fourth. Gallen didn't allow another baserunner until Suzuki provided the game's first hit with a one-out single in the fifth.
—Field Level Media