Stanton, who hit a solo shot in the sixth, is two homers shy of Gary Sheffield's franchise record of 42, set in 1996.
Miami snapped a 3-3 score in the eighth when Christian Yelich singled, advanced on a walk to Marcell Ozuna and scored on Dietrich's soft single to center. Tomas Telis, who started the day hitting .161, drilled a two-run triple to cap the rally.
Nolan Arenado, who had a two-run shot and leads the majors with 100 RBIs and 66 extra-base hits, and Gerardo Parra hit homers early in the game for the Rockies.
In the third, Parra threw out Dee Gordon, who slowed down while trying to go from first to third on a single. In the fourth, Parra threw out Ozuna trying to stretch a single into a double.
But the heroics from Arenado and Parra weren't enough for the Rockies (65-50), who started the day atop the NL wild-card race.
Miami (54-60) snapped a two-game losing streak.
Neither starting pitcher -- Jose Urena for Miami or Jon Gray for Colorado -- finished the sixth inning, and both got no-decisions.
Junichi Tazawa (2-2) earned the win after pitching a scoreless eighth. Rockies reliever Jake McGee (0-2) took the loss.
Colorado opened the scoring in the third. Charlie Blackmon led off with a ground-rule double that hopped the fence in right-center. One out later, Arenado hit his opposite-field homer to right-center, going with a pitch that was low and outside.
Miami cut its deficit to 2-1 in the fifth. Dietrich singled, advanced to third on a hit-and-run single by Telis and scored on a double-play grounder.
Parra's sixth-inning homer, which was pulled to right, put Colorado ahead 3-1. But the Marlins tied the score in the bottom of the sixth on Stanton's homer and a sacrifice fly by J.T. Realmuto.
Miami's Brad Ziegler pitched the ninth, earning his third save in six tries. The game ended with a fielding gem by shortstop Miguel Rojas, retiring Blackmon at first.
NOTES: Bruce Sherman, a venture capitalist from New York, leads a group that has reportedly purchased the Marlins from Jeff Loria for $1.2 billion. Former New York Yankees shortstop Derek Jeter will reportedly run the baseball personnel operation. ... The Marlins have won seven of their past eight series against the Rockies, with one split. ... Miami optioned LHP Hunter Cervenka to Triple-A New Orleans and recalled LHP Justin Nicolino. ... Rockies LHP Mike Dunn spent the past six years with the Marlins. ... Rockies bench coach Mike Redmond and first-base coach Tony Diaz have strong Miami ties. Redmond won a World Series ring with the Marlins' 2003 team and managed the franchise from 2013 to 2015. Diaz played at Florida International University.