Dundee United came back from the dead to snatch victory in a game which St Mirren had dominated virtually throughout.
It must have been a hard one to swallow for Gus McPherson's troops but one which allowed United to leap-frog Aberdeen into third place.
The visitors had set their stall from the second minute when the ball crashed off the post. In-form Andy Dorman took advantage of slack defending to steer a low shot past the sprawling Lukasz Zaluska but off the base of the upright.
And with United at sixes and sevens, St Mirren were unlucky again in the tenth minute when Craig Dargo's cross was forced on to the bar by Billy Mehmet and the rebound fell to Dargo whose net-bound shot deflected away off his own player.
But the visitors took a deserved lead in the 17th minute with a screamer from Jack Ross. Picking up possession on the right flank he cut inside and hit the ball high into the net past Zaluska, who could be faulted for his positioning.
This was too much for Craig Levein who sped down from the stands to let rip at his players.
It seemed to temporarily stem the constant flow towards his keeper but, nevertheless, Hugh Murray had a great chance in the 39th minute scooping over the bar from 12 yards when it seemed a certain goal.
The second period began a little better for the hosts with Jon Daly going close in the 47th minute and then, a couple of minutes later, a Garry Kenneth knock-down was smashed over the bar from Craig Conway.
United equalised in the 72nd minute when Franco Miranda gave the referee no option bringing down Lee Wilkie for Warren Feeney to thump home the penalty.
But Wilkie became sinner two minutes later when the referee awarded a penalty at the other end for a reckless tackle by him on Dargo. Mehmet easily tucked it away.
Danny Swanson missed a glaring chance in the 80th minute when Kenneth's volley had been brilliantly blocked by Scott Cuthbert and the sub blasted over the open goal.
But United were level again in the 84th minute thanks to a 20-yard shot from Prince Bauben which the keeper seemed to have covered and then lost in mid-air.
And there was worse to come for the visitors as they lost the game two minutes later. A superb run from Swanson ended with Francisco Sandaza hitting the ball low across goal for Warren Feeney to arrive at the back post and slot it in.