This Scottish Premiership match looked to be heading for goalless draw when Carey struck after good work from County sub Melvin De Leeuw.
The home side created the first decent opening in the 10th minute when Scott Boyd lobbed the ball in for Gary Glen but Frazer Wright stepped in to clear the danger.
In the next attack Alex Cooper whipped in a ball from the left but Steven Anderson guided the ball behind for a corner.
At the other end Nigel Hasselbaink tried to set up Stevie May but the ball ran away from him as County goalkeeper Michael Fraser gathered.
The home side were doing most of the pressing and a Carey free-kick was knocked down by Brian McLean - but Boyd failed to make proper contact.
The home side came close to an opener in the 21st minute when Greek defender Evangelos Oikonomou swung over a deep cross from the left and Jordan Slew rose at the back post to head narrowly over.
Play got bogged down a bit in midfield for a spell but things livened up in the 40th minute when Gordon crossed for Slew, who forced a fingertip save from Alan Mannus from the edge of the 18-yard box.
Saints then broke up to the other end and Hasselbaink's ball into the danger area but Stuart Kettlewell was alert to the danger.
County forced a corner in the opening minute of the second half but it was Saints who created the first real opening when Hasselbaink broke before laying the ball off for Chris Millar, who curled it just beyond Fraser's left hand post.
The home side pushed for an opener and Cooper flashed the ball across goal as Glen just failed to connect.
County kept the pressure on and there were claims for handball as a Slew drive was blocked en route to goal.
Both sides made changes in an effort to make the breakthrough with Saints new signing Michael O'Halloran coming on for Hasselbaink and De Leeuw replacing Glen up front for County.
Saints were seldom seen as an attacking force in the second half and with just two minutes remaining Carey grabbed the winner for County.
De Leeuw dispossessed Wright on the flank and squared the ball for Carey, who rolled the ball into the net from 12 yards.
Saints were awarded a free-kick on the edge of the area in the final minute but David Wotherspoon's shot was easily held by Fraser.
In the dying seconds on-loan signing Michael Tidser, who came on as a late sub, flashed a long-range shot narrowly past Mannus' left hand post as the hosts finished the contest on the front foot.