Andy Kirk gave Dunfermline a deserved first-half lead when he ran onto Andy Barrowman’s flick-on to finish low beyond Paul Gallacher.
Greg Tansey equalised with a deflected strike a minute into the second-half, before Kirk restored the lead only five minutes later.
Terry Butcher’s side were looking to avoid a third consecutive defeat and responded well in the final quarter of the game.
Jonny Hayes took advantage of a Paul Gallacher fumble to equalise on 76 minutes and Inverness took the lead with only eight minutes remaining when Tansey scored his second with a header at the back post.
There was one final sting in the tale, however, as Dunfermline skipper Hardie curled a wonderful free-kick beyond Ryan Esson in the final minute.
Dunfermline had not played in the Clydesdale Bank Premier League for 12 days and they started brightly, Esson saving from Kirk after only two minutes.
Jason Thomson, on loan from Hearts, was next to threaten but his shot was parried by the Inverness keeper but Esson was powerless to stop Kirk opening the scoring with a cool finish on 26 minutes.
Last season’s First Division champions were causing a real threat down both wings through Cardle and Paul Burns and after another Cardle cross was cleared to the edge of the box, Hardie fired just wide.
Inverness had barely caused a threat in the first-half but they were level within a minute of the second.
The dangerous Tansey showed a fine piece of skill to create some space on the edge of the box before his shot was deflected and looped beyond Gallacher in the Dunfermline goal.
Dunfermline responded immediately and were nearly back in front when Cardle’s chipped cross to the back post was headed just over from Barrowman.
The Pars were back in front five minutes later though when shambolic defending from Inverness left Kirk all alone only six yards out to easily nod another Cardle cross into the net.
With the game becoming increasingly stretched there was plenty of opportunity for both sides to counter-attack and Cardle threatened again on the break but his cross from the left was glanced wide by Barrowman.
Caley Thistle should have been level for the second time when Doran’s cross was headed towards goal by Richie Foran.
The ball appeared destined for the net but Gregory Tade inexplicably applied the final touch when in an offside position and the goal was disallowed.
Spurred on by that disallowed goal Butcher’s men had undoubtedly their best spell of the game in the final quarter. Hayes’ effort from 20-yards was fumbled by Gallacher but collected at the second attempt.
There was to be another uncomfortable moment for the former St Mirren goalkeeper as Inverness got back on level terms with just under 20 minutes remaining.
Owain Jones’ shot from 30-yards was spilled by Gallacher and Hayes pounced to slide in his first goal of the season.
Moments later the visitors were nearly in front when Esson’s long ball upfield was knocked on by Foran and substitute Nick Ross almost made an immediate impact with a fine strike that swerved just wide.
In an end-to-end encounter, Barrowman almost had Dunfermline back in front with a rising drive from 18-yards but was denied by an excellent one handed save from Esson.
Caley Thistle took the lead for the first time in the game with only eight minutes remaining when Tansey scored his second with a simple header after Ross Tokely had headed across goal.
All hope looked lost for Dunfermline but they were saved by a Hardie’s wonder goal right on 90 minutes. The midfielder curling a fully 30-yard free-kick high into the net beyond Esson’s despairing right-hand.