Debutant Lewis Guy had given the hosts the lead just after the half hour mark with an accurate angled drive beyond Ryan Esson but two goals in the final 20 minutes from Nick Ross and Billy McKay had appeared to have handed the visitors all three points.
However, McGregor was in the right place at the right time to head home when Esson completely misjudged a cross from the right.
And in the aftermath of the goal Saints were reduced to 10 men as Guy was sent-off for clashing with Ross Draper in his attempt to get the ball out of the net.
Inverness manager Terry Butcher had handed debuts to David Raven, Gary Warren, Simon King and Draper but it was the visitors who were the first to settle as McKay curled a shot just wide inside three minutes before Andrew Shinnie had a great chance to give the visitors the lead - but pulled his effort wide when through on goal.
However, Saints eventually started to get into their rhythm and twice could have been ahead through a former Caley Thistle player as Dougie Imrie fired a dipping volley just over and was then denied by a fine save from Esson.
Guy then missed a glorious chance to open his St Mirren account as he mistimed his header from Gary Teale's pinpoint cross and the ball floated harmlessly over.
However, the former MK Dons striker made amends four minutes later as a lovely move involving Teale and Paul McGowan found him free on the right side of the area and he drove the ball low beyond Esson into the net.
Inverness responded well to going behind and were nearly level before half-time when a corner from the left fell to Draper on the edge of the area and his rasping drive beat Craig Samson but was headed off the line by Teale.
Moments after the break Guy had a similar chance to the one with which he scored but this time Esson managed to get down to block his goalbound effort.
Aaron Doran was looking like the most likely to get Inverness back in the game and he created an opening with a neat piece of skill inside the area and a low effort which forced Samson into a fine fingertip save.
The game then became increasingly stretched and scrappy as both sides tried to cope with an almighty thunder and lightning storm but just as the rain eased Inverness were level as Doran's deflected cross fell perfectly for substitute Ross to tap home at the near post.
Doran was involved again as Butcher's men went in front six minutes later as Shinnie slid the ball through for McKay and he kept his cool to slot low beyond Samson.
St Mirren pushed forward desperately in search of an equaliser but seemed to have been denied when Esson produced a flying save to turn Sam Parkin's thunderous volley over the bar in stoppage-time.
However, seconds later the goalkeeper flapped at a cross from the right and McGregor was on hand to head into the empty net.
Further controversy followed as Guy was dismissed in the aftermath of the goal for pushing Draper, but there was no time for Inverness to make their man advantage count as the spoils were shared.