Liam Millar’s 87th-minute goal ended Kilmarnock’s eight-game winless league run and keeps St Mirren bottom of the Scottish Premiership.
The substitute tapped in Eamonn Brophy’s cross – the first goal his side has scored in six matches.
Steve Clarke’s visitors, who struck the post through Brophy earlier in the second half, move within a point of third-placed Aberdeen.
St Mirren remain a point adrift of Dundee at the bottom.
The defeat is the first Oran Kearney’s side have suffered in four games.
Forgettable game produces late drama
With the rain teeming down, the first half was eminently forgettable, the play pedestrian and chances frugal.
St Mirren lost their captain Stephen McGinn to an injury sustained during the warm-up. Kyle McAllister was at the heart of their best forward raids, his involvement lacing flourishes of quality through a drab opening period. He lashed a volley narrowly wide and sent Simeon Jackson galloping towards goal, the striker drawing a comfortable save from Daniel Bachmann.
At the other end, Brophy’s cries for a penalty were waved away when he went down inside the St Mirren box. Ethan Erhahon had jabbed a boot towards the Kilmarnock striker as he shimmied and spun, and while there was contact it was not enough to flatten Brophy.
The Kilmarnock forward came close in the final throes of the first half, bending a fine, dipping free-kick just over the crossbar from around 25 yards out, and closer still six minutes into the second.
Jordan Jones made his first telling rampage up the left and cut the ball back for Brophy, who swivelled on to his left foot and crashed a shot of the post.
That seemed to raise the tempo and spark the game into life. Kilmarnock began to take control, but they couldn’t end their goal drought. They had another, stronger, shout for a penalty when Ryan Flynn caught Rory McKenzie as he attempted to control Stephen O’Donnell’s pass.
St Mirren almost hit their visitors on the break. Jackson was sent deep into the box where his effort was stopped by a brilliant block from Stuart Findlay on the slide, before Brophy thundered a second free-kick off-target at the other end.
The pattern continued. Kirk Broadfoot headed straight at Vaclav Hladky from a free-kick and off went St Mirren, another outstanding Findlay tackle winning the ball and levelling Jackson as the striker cocked his leg to shoot.
In the final 10 minutes, St Mirren rallied, having taken Kilmarnock’s punches and sensing they could land a telling shot of their own. A teasing Jackson corner evaded everyone when all it needed was a decisive touch, before the Canadian flicked Paul McGinn’s cross wide on the volley.
But it was Kilmarnock who struck the killer blow, Liverpool loanee Millar racing clear to knock Brophy’s ball home at the back post. A long-awaited, morale-boosting win for Clarke’s men. A devastating finale for Kearney’s.
Crafty Killie get their rewards – analysis
Livingston manager Gar Holt on BBC Sportsound
It was pleasing to see both sides upping their game in the second half. Killie just had that little bit of extra craft. They’re fourth in the table and the difference showed. On balance of play, they deserved it.
There’s a lot of positives for St Mirren. They had chances and lost to a last-minute goal against the team fourth in the league. If they get the same performance on Saturday against St Johnstone they could get the points.
‘Just reward’ for Kilmarnock – reaction
Kilmarnock manager Steve Clarke: “The goal was a long time coming. It was nice to see the ball hit the back of the net. We’ve had a tough run. The boys have put in a lot of effort. I thought that was just reward for their efforts.
“Second half, there was only one team trying to win it. We got caught a couple of times on the counter attack. We had to defend quite desperately. We got away with it. We kept pushing and pushing.
“I think we had three maybe four in total penalty claims. There was one definite one. The one on Rory Mckenzie second half is a definite.
“It’s nice to get within a point of Aberdeen. Hopefully we can close them down, certainly keep in touch with them after the split and see what happens.”
St Mirren manager Oran Kearney: “It’s a hard one to take. That’s the joys of football – we scored a last-minute winner last week and now we’re on the receiving end.
“We’ve come a long way in the last few weeks, the manner of performance shows we’re definitely making progress, and it’s important we kick on again. I still absolutely believe survival is possible.”