Aberdeen kept their top-six hopes alive thanks to a stoppage time strike from substitute Chris Maguire to break the hearts of the Inverness players in an action-packed encounter in the Highland capital.
The home side were first to show and Derek Soutar did well to parry a Don Cowie drive after three minutes.
However it was the Dons who went in front in the eighth minute when Lee Miller picked out Sone Aluko with an intelligent ball. The on-loan Birmingham star cut inside, left two defenders in his wake and fired a low drive past Michael Fraser to the keeper's right.
Caley had a penalty claim turned down when Dave Bus tangled with Marius Niculae and then Lee Miller fired an ambitious effort over the bar.
Inverness levelled against the run of play in the 20th minute when a Russell Duncan free-kick found the head of Dutch defender Bus who, in trying to knock the ball away for a corner turned the ball into his own net.
Fired up by the leveller, the home side took charge of proceedings and Soutar did well to save from Niculae after 24 minutes. The Romanian then had a penalty claim turned down when he clashed with Alan Maybury, although it looked all the way like a well-timed tackle.
With six minutes of the first half to go Doug Imrie found Cowie, who in turn laid the ball off for Russell Duncan who fired an unstoppable shot past Soutar to make it 2-1. The scorer was then promptly booked for unwisely running to the fans of his former club to celebrate his strike.
It was end to end stuff and with the interval approaching a pinpoint Richard Foster cross was headed home by Barry Nicholson with the home defence posted missing.
The whistle went seconds later and Duncan petulantly thumped the ball into the stand to stupidly earn a second yellow.
Maguire replaced Bus at the break and the Dons began the second half brightly, using the extra man to their advantage. Nine minutes after the restart they were rewarded when Nicholson's corner was headed home by Miller for his eleventh goal of the season.
Not to be outdone, the ten men pushed forward and in 58 minutes Niculae and Cowie combined to send Roy McBain clear of the Dons defence, the midfielder beating Soutar with a clinical finish.
With time running out the game was becoming very stretched and substitute Markus Paatelainen should have done better with two minutes to go, shooting weakly at Soutar.
In the fourth minute of stoppage time the Dons mounted one last attack and Stuart Duff bravely headed the ball to Jackie McNamara, taking a boot in the face for his troubles.
The ex-Celt rasped in a shot that Fraser could only parry, the ball flew into the air and fell to Maguire who headed home to spark great celebrations among the visiting fans.
Although never a dirty game, the referee flashed eight yellow cards for a variety of offences, while home skipper Grant Munro was given a straight red after the final whistle for speaking out of turn.