The Czech ace slammed home a Craig Thomson corner in injury time just minutes after Ryan Stevenson had equalised at Tynecastle.
Michael Higdon gave the visitors a deserved half-time lead with a 15th-minute header to make up for an earlier miss but Skacel's dipping effort brought Hearts level in the 55th minute.
Stevenson then cancelled out Higdon's second before Skacel pounced in the box to seal Hearts' first win in four games.
Hearts goalkeeper Marian Kello was forced into action after just 60 seconds to push Higdon's close-range header clear.
Steven Thomson found Arron Mooy on the right flank after being gifted possession by Adrian Mrowiec and the Australian's delivery from the right flank was met by Higdon, but the Englishman failed to get any real power on his effort.
Higdon was left red-faced when he squandered an even better chance in the sixth minute. Steven Thomson made it to the byline and his low ball across the six-yard box found the unmarked frontman but he completely fluffed his shot.
The away side, however, deservedly took the lead in the 15th minute through Higdon. Kenny McLean's free-kick was knocked across the box by Darren McGregor and Higdon angled a header over the line from eight yards despite Craig Thomson's attempt on the line to prevent a goal.
St Mirren were then denied a second goal by the woodwork after 30 minutes when Paul McGowan crashed a shot from Steven Thomson's pass off the inside of the post and Craig Thomson made a timely block on Mooy on the rebound.
With the Hearts defence in disarray, McGowan then volleyed a fierce shot straight at Kello from inside the box after connecting with McLean's deep cross.
Hearts fans' frustrations grew as they watched their side offer little hope of mounting any kind of fightback against a spirited St Mirren team.
Following an abject first-half performance, it was no surprise that Hearts manager Jim Jefferies made changes at the interval.
Andy Driver and Scott Robinson were both introduced for Mrowiec and David Obua.
Hearts began the second half with greater zest about their play and David Templeton hit a rising shot over the bar from the edge of the box after latching onto Stephen Elliott's knockdown.
Skacel then nodded a tame header straight at Gallacher from Palazuelos' cross.
But the Czech Republic cap hit the target in the 55th minute as he brought his team level with a superb strike from outside the box. Skacel, who scored a hat-trick in October's victory over the Buddies, raced onto Lee Mair's defensive header and drilled a dipping shot into the corner of the net.
Higdon restored St Mirren's lead in the 68th minute when he turned Andy Webster in the box and curled a clinical left-footed shot high into the corner of the net.
Skacel came close to levelling the score again with a superb acrobatic effort from 12 yards that was expertly palmed over the bar by Gallacher.
From the resulting corner, the midfielder then slammed a low shot into the advertising boards.
Hearts were level for a second time in the 82nd minute through substitute Stevenson. Stephen Elliott held the ball up inside the box for Stevenson to race in and drill a left-footed shot past the goalkeeper.
The former Ayr United midfielder then had a volley deflected wide for a corner after Webster headed the ball into his path.
Hearts completed a remarkable comeback in injury time when Skacel turned in Thomson's corner following a goalmouth scramble.