Iain Vigurs opened the scoring for County after 10 minutes and despite Thompson's leveller on 39 minutes, Grant Munro restored the visitor's lead on the stroke of half-time.
Three St Mirren goals in the space of 10 minutes turned the game in the favour of the home side as Lewis Guy levelled from the penalty spot, Sam Parkin beat Michael Fraser to net the third and Kenny McLean drilled a low shot from outside the area into the bottom right-hand corner.
County refused to give up, however, and Rocco Quinn netted with 10 minutes remaining and again 90 seconds later to level the game at 4-4.
But as the clock approached the 90-minute mark, Thompson got on the end of Graham Carey's precise cross to beat Fraser in stunning style and earn St Mirren three points which takes the host third in the table.
Celtic leapfrogged Motherwell to the summit by dismantling the Steelmen in impressive style at Fir Park.
On-form striker Gary Hooper opened the scoring in the 31st minute with a low drive before Well defender Adam Cummins put Scott Brown's cross past Darren Randolph and into his own net four minutes later.
Cummins was sent off soon after the break by referee Iain Brines for a last man challenge on Kris Commons but Brown saw his second penalty in a week saved.
Well drops to fifth in a congested table as Kilmarnock and St Johnstone also won, the former beating Heart of Midlothian 3-1 thanks to Cillian Sheridan's hat-trick.
The Irishman opened the scoring with a first-half header before doubling the away side's advantage five minutes after the restart.
He completed his hat-trick by capitalising on an error from Hearts goalkeeper Jamie McDonald before Marius Zaliukas scored a late consolation for the home team.
St Johnstone secured its third league victory in a row to leave Tayside rival Dundee deflated at the foot of the table.
First-half goals from Gregory Tade and Liam Craig allied to Steven MacLean's second-half breakthrough meant Ryan Conroy's brief equaliser mattered little.
Richie Foran's quickfire double helped Inverness hammer Dundee United 4-0 and secure its first league win of the season.
The Irishman curled in a beauty in the 31st minute and netted a close-range header four minutes later.
Andrew Shinnie increased the lead on 70 minutes when he bundled the ball across the line and a screamer from teenager Philip Roberts rounded off the win two minutes later.
Gavin Rae's second-half strike gave Aberdeen its first home win in the Scottish Premier League this season with a 2-1 victory over Hibernian.
Niall McGinn opened the scoring after Ben Williams had parried a Scott Vernon effort with only four minutes gone and, after a stunning equaliser from Irishman Eoin Doyle after 33 minutes ensured the sides went in level at the break, the winner arrived after 70 minutes when substitute Josh Magennis cut the ball back for midfielder Rae to net from close range.