The Pittodrie wind meant the opening exchanges were relatively tame, with neither side able to exert any control on the game, though the home side perhaps made the better of the early running. It was almost midway through the first half before Niall McGinn's free kick, wide of the target, signalled the first real chance.
But the home side opened the scoring after 28 minutes when the County defence failed to deal with a McGinn corner, leaving Main with all the time in the world to sweep home the opening goal from two yards.
However they were down to 10 men just after the half hour, as teenager Campbell, having earlier been booked for a foul on Josh Mullin, was shown a second yellow for not retreating the appropriate distance at a free kick.
The Dons could have extended their lead as Cosgrove found himself through on goal only to be denied by Ross Laidlaw, with Main sending the follow-up over the bar.
The visitors levelled the scores two minutes before the interval as former Don Ricky Foster found McKay with a cross to the back post which the Northern Irishman headed past Joe Lewis almost in slow motion.
Despite County's man advantage, the game remained pretty even, though Scott McKenna was relieved after McKay seized upon his loose backpass, only for Lewis to save with his feet, and then also block Lee Erwins follow-up.
A minute later, Lewis Ferguson saw his shot from the edge of the area tipped onto the post by Laidlaw, with the goalkeeper also saving from McGinn on the follow-up.
Both teams were able to held each other at arms length for the majority of the second half, but with 10 minutes remaining, Mullin's half-volley had Lewis at full stretch to push round the post.
However the winner came as McKay stole in behind the home defence to lash an angled strike across Lewis to earn his side the points.