The full-back grabbed the only goal of the game in front of a crowd of 16,443 at Tynecastle, in what was the first home fixture since the full extent of the club’s problems were revealed.
St Mirren have now lost six SPL games in a row and sit just a single point above bottom side Dundee.
Hearts appeared to be galvanised by their recent troubles and Saints were forced to deal with an early period of pressure.
A Grainger free-kick from the right found Callum Paterson in the box and his header was deflected just over the crossbar. Darren Barr then attempted to set up Jamie Walker, on his first senior start, in front of goal but his header was smothered by an alert Craig Samson.
The home side continued to press for the opener and the goalkeeper was called into action again, this time to block a powerful free-kick from Grainger.
Chances for the visitors were scarce early on and Hearts threatened again when Barr saw his low effort fizz just past the post, with Ryan Stevenson’s shot also off target moments later.
At the other end, Steven Thompson had a rare chance for Saints but squandered the opportunity by blasting well over as the first half ended goalless.
For all their possession, Hearts also struggled to break down Saints after the break and made their first change on the hour mark when Paterson was replaced by Novikovas.
He quickly had a part to play in the breakthrough with a short free-kick to Grainger, who sent a lovely swerving effort past the grasp of Samson and into the top corner after 63 minutes.
Later, Grainger claimed his shot was handled in the box by Goodwin as Hearts chased a second goal but there was no spot-kick award from referee Bobby Madden.
Hearts goalkeeper Jamie MacDonald had enjoyed a reasonably quiet afternoon but was called into action to block well from a Kenny McLean free-kick from 25 yards out. Jason Holt then cleared a Marc McAusland header off the line as the home side held on for the win.