The Red Wings have won back-to-back games for the first time this season and they ended the four-game St. Louis winning streak. It was only the second setback of the year for the Blues.
Zetterberg scored the game's first two goals in the opening 8 minutes, but St. Louis climbed back into a 2-2 tie by the end of the first period on scores from Kevin Shatterkirk and Matt D'Agostini.
Patrik Berglund tallied on the power play for the only goal of the second period to put the Blues in front, but the Red Wings delivered a three-goal third period.
Jonathan Ericsson tied it with a slap shot 4:31 into the third and Pavel Datsyuk produced the go-ahead goal with 8:05 left. Zetterberg, who also had two assists, completed the fifth hat trick of his career with 13 seconds remaining.
Jimmy Howard stopped 23 shots for the Red Wings. St. Louis goaltender Jaroslav Halak was pulled from the game after giving up Zetterberg's two early goals and was replaced by Brian Elliott, who stopped 17-of-19 shots.
St. Louis had recorded a 6-0 win over Detroit earlier in the season.