After a quiet opening 20 minutes, it was the home side that had the first real chance of the night when Sebastian Freis attempted to fire in a rebound after Sven Ulreich had punched a Marc Torrejon effort clear.
Freiburg continued to look the stronger side as Oliver Sorg charged into the box, but the Stuttgart defenders made sure that his effort did not reach their keeper.
Stuttgart's lead did not last long though, as Freiburg hit back just before the break when Vladimir Darida unleashed a powerful strike from 30 yards out.
The visitors edged back ahead shortly after the restart as Carlos Gruezo carved out some space on the edge of the box before picking up the top corner.
Ulreich had to remain alert down the other end to stop the hosts equalising again, but the keeper tipped Admir Mehmedi's effort over.
Stuttgart opened up a two-goal cushion for the first time with just over 20 minutes to play as young striker Timo Werner met a Leitner cross, allowing him to head in from the edge of the box.
Things got worse for Freiburg a few minutes later when Stefan Mitrovic was shown a straight red card for a wild challenge on Harnik on the edge of the box.
It did not take Stuttgart long to capitalise against the 10 men of Freiburg, with Gotoku Sakai setting Harnik up with a through-ball, giving the forward an easy finish from close range.
Adam Hlousek came close to making it five in the final moments of the match, but the keeper managed to pull off a fingertip save to keep his shot out.
The win moves Stuttgart out of the bottom two, while Freiburg, who had been unbeaten in three, stay 14th.