Carey bagged his dramatic winner after good work from substitute Melvin De Leeuw, as the hosts won back-to-back games for the first time this season.
County had the better of the game early on but Frazer Wright cleared Scott Boyd’s dangerous pass before Boyd failed to make proper contact with Brian McLean’s knockdown.
Nigel Hasselbaink tried to set up Stevie May at the other end but home goalkeeper Michael Fraser was able to gather.
And the hosts were soon in charge again, Jordan Slew heading just over the bar after Evangelos Oikonomou had sent over a deep cross from the left.
Slew then went close again just before the break, producing a lovely volley on the turn after Ben Gordon had crossed, drawing a fingertip save from Alan Mannus.
Saints had a chance just after the interval when Hasselbaink made an opportunity for Chris Millar, who curled his shot wide of the post.
David Wotherspoon then had an effort saved by Fraser but the hosts gradually took control again and Gary Glen almost got on the end of Alex Cooper’s cross.
County then appealed for handball when a Slew shot was blocked but it looked like they might have to settle for a point until a late mistake from Wright.
The St Johnstone man was robbed by De Leeuw, who then squared the ball so Carey could roll a shot into the net.
County sought to double their lead and, in the closing moments, on-loan signing Michael Tidser, who came on as a late sub, flashed a long-range shot narrowly past Mannus’ left hand post.
But one goal proved enough for the hosts, who moved up to 10th in the table.