The Welshman took full advantage of a sweeping move involving Greg Leigh and fellow substitute Niall McGinn to lash the ball high into the roof of Bobby Zlamal's net to give Aberdeen a victory that had only looked in doubt for about ten minutes in the second half.
The consolation for Hearts fans was that period coincided with the return of Naismith, meaning the LA Philharmonic's concert last Friday night is now unlikely to be the only entertainment on view at Tynecastle between now and next May.
It only took seconds after coming off the bench for last season's top scorer to mark his permanent return from Norwich City with what until that point looked an unlikely equaliser with his first touch, a diving header after Craig Halkett had helped on Michael Smith's long throw.
Ten minutes later Aberdeen must have felt like they had been mugged as Naismith's pass to Uche Ikpeazu led to the big striker threading an equally incisive ball through ball for Jamie Walker's adroit finish to give them an improbable lead.
Any thoughts of only a second league win in ten games dating back to March evaporated though as indiscipline finally caught up with a team who had four players booked and Aaron Hickey sent off at a key moment.
The teenager's second yellow and a red for a needless foul on substitute McGinn was compounded when Clevid Dikamona clattered into the back of the same player when contesting the resulting free kick to concede a senseless penalty.
Cosgrove lashed that home, just as he has done with three previous spot kicks in Europe this season, to add to his early opener yesterday and take his tally to eight goals in five games this season and 27 in the last 33 overall.
Hedges then made sure Aberdeen head for Croatia and Thursday's Europa League 3rd round qualifier against Rijeka in high spirits while Hearts' trip back the capital was made all the more depressing by the news that the injury that forced John Souttar off in the first half looks like being ankle ligament damage.
Aberdeen in general, and Cosgrove in particular, had picked up where they left off against Chikhura Sachkhere last Thursday night and they could have been two goals ahead as quickly as they had been in that Europa League tie.
A double during a blistering opening 20 minutes of the eventual 5-0 drubbing handed out to the team from Georgia really should have been replicated here as Hearts struggled to come to terms with the pace and variety of the home side's attacks early on.
Scott Wright and James Wilson replaced McGinn and Hedges as McInnes freshened-up his starting X1 and in the initial stages the pair showed what a shrewd decision that was.
Wright provided the wall for Jon Gallagher's cleverly worked short corner before the latter produced the perfect pass from the return for the late arriving Wilson only for the former Manchester United striker to scoop the ball over the bar.
It was left to Cosgrove to give his team mate a lesson in composed finish, although Christophe Berra should feel disappointed at the assist he provided when failing to deal with Andrew Considine's long ball forward.
The Hearts skipper clearly thought goalkeeper Zlamal should shoulder the blame for what happened next as Cosgrove sped through to bend the ball into the far corner of the net from tight angle but it was Berra's miscued header and lack of recovery pace that was key.
No such problem for Aberdeen though with Wright's speed was so unnerving for Hearts that both Hickey and Sean Clare were cautioned long before the interval for their crude response to the threat posed by someone who spent the second half of last season on loan at Dundee.
Hickey for a cynical trip as the speedy striker threatened to race clear from the half way line that was to prove much more costly later on, while Clare clattered into his opponents ankle when the ball had already departed the immediate vicinity.
Although on a different day it could have been worse for the Tynecastle team as Uche Ikpeazu after his elbow caught Scott McKenna flush in the face but referee Don Robertson rightly judged it to be clumsy rather than malicious.
The yellow card looked the sensible decision as was the one issued to Aberdeen midfielder Lewis Ferguson when a stray arm caught Hearts impressive youngster Andrew Irving at the start of the second half.
Shay Logan and Jake Mulraney were also booked for fouling each other in separate incidents along with the Dons midfielder Funso Ojo while Hedges was cautioned for his celebrations for the winner, which overall gives you a fair indication of how disjointed and physical the game degenerated into after a bright start.
Berra nearly made amends for his error at one end with the nearest the visitors came to an equaliser at the other in the first half, only for Joe Lewis to tip his fellow captain's diving header over the bar.
Once again Levein's side only really looked a threat from set pieces and Craig Halkett might have scored on the stroke of half time if the central defender had got greater contact on another well delivered Irving free kick.
Unfortunately the Jambos manager had been forced to alter his backline by then as John Souttar was forced off injured six minutes from the interval with Dikamona taking over but there wasn't much goalmouth action until it all kicked-off late on.
Aberdeen: Lewis, Logan, Considine, McKenna, Leigh, Gallagher (Anderson 81), Ferguson, Ojo, Wright (Hedges 61), Wilson (McGinn 67), Cosgrove. Subs not used: Cerny, Ramsay, Campbell, May.
Hearts: Zlamal,Souttar (Dikamona 39), Berra, Halkett, Smith, Walker, Clare, Irving (Naismith 66), Mulraney (Washington 66), Hickey, Ikpeazu. Subs not used: Doyle, White, Bozanic, Cochrane.
Referee: Don Robertson