The Austrian striker scored the all-important goal in the third minute, before Stuttgart were unnecessarily made to sweat on the points by failing to add a second.
They had the better of the game at the Rhein-Neckar Arena and were relieved in the end that one goal was enough to see off their local rivals - who remain third from the bottom of the table, now 10 points adrift of safety.
Stuttgart brought an end to their sequence of defeats by drawing 1-1 with Genk in the Europa League on Thursday night, but they now had to do the same in the Bundesliga.
There was a spring in their step after that result, though, and Harnik put them in front in the third minute when he headed Ibrahim Traore's cross in off the underside of the crossbar.
Hoffenheim were caught cold as they have been in each of their last three games, yet there did not seem to be a reaction forthcoming from Marco Kurz's men.
Instead, Stuttgart dominated proceedings, going close with Traore and Vedad Ibisevic, but failing to land a crucial second blow.
Hoffenheim were always in the game at just a single goal behind, yet Sven Ulreich in the Stuttgart goal was rarely tested.
Heurelho Gomes was having a busier night at the other end, though, and he kept out a powerful Traore shot as Stuttgart sought a second goal.
In the end, Stuttgart did not need another breakthrough to secure their first win of 2013 and end a sequence of five successive league defeats, leaving their local rivals in serious relegation danger with 12 games of the season remaining.