Aaron Doran's dramatic injury-time header gave Inverness a 2-1 William Hill Scottish Cup quarter-final win over Dundee United at Tannadice.
Midfielder Joe Chalmers gave the visitors the lead in the 19th minute with a wonderful strike, then hit the bar for the lively Highlanders.
Robbie Neilson's side came back, however, and attacker Nicky Clark, who scored from the spot in the 1-0 Ladbrokes Premiership win over the Highlanders at the same venue on Tuesday night, levelled in the 68th minute with another penalty.
However, in the first minute of added time, a long throw from Brad McKay ended up inside the six-yard box and Doran threw himself to knock it into the net and put Inverness into the last four for the first time since they won the tournament in 2015.
After beating the visitors in midweek, Neilson made two changes his side with captain Fraser Fyvie replacing suspended Calum Butcher, while Cammy Smith came in for Paul McMullan – who started on the bench.
Inverness captain Carl Tremarco, Jamie McCart and Doran came back into a Highlanders' side which dominated most of the first half.
United goalkeeper Benjamin Siegrist made saves from Doran and Coll Donaldson in the enthusiastic early stages.
Striker Jordan White then headed a free-kick from Liam Polworth's free-kick over the bar and when they took the lead it was well deserved.
Chalmers took a pass from Polworth, worked the ball on to his left foot and from just inside the box curled his shot past Siegrist and into the far corner for his first goal of the season.
Three minutes later the 25-year-old former Celtic and Motherwell player crashed a volley off the bar from 10 yards, after Doran's cross had deflected into his path.
That let-off seemed to spark United into life and a great Tremarco block stopped Peter Pawlett's drive testing Inverness keeper Mark Ridgers.
The Terrors stepped up their efforts after the break.
McMullan replaced Smith in the 53rd minute but minutes later, after Pawlett fouled Tremarco wide on the left, Polworth fired in a free-kick which Siegrist punched away to safety.
Then, as Inverness attacked again, midfielder Charlie Trafford drilled in a shot from 25 yards which fizzed a yard past the post.
Morgaro Gomis came on for Fyvie in the 63rd minute, just before Ridgers pulled off his first real save from a McMullan drive.
United's penalty was awarded soon afterwards when McMullan tumbled to the ground inside the box, it seemed rather easily, under a challenge from White.
After referee Steven McLean pointed to the spot to enrage the Inverness players, Clark drove the ball low past Ridgers.
Then Inverness responded, Polworth playing in White but he was thwarted by Siegrist and then substitute Nathan Austin, on for Trafford, headed in a Sean Welsh free-kick – only to be ruled offside.
However, just when it looked like the match was going to a replay, there were ectastic scenes among the Inverness fans, management and players when McKay's throw-in was flicked on by White for Doran to head past Siegrist.
ga('create', 'UA-72310761-1', 'auto', {'name': 'pacontentapi'});
ga('pacontentapi.set', 'referrer', location.origin);
ga('pacontentapi.set', 'dimension1', 'By Ronnie Esplin, Press Association Sport');
ga('pacontentapi.set', 'dimension2', '2da8e4ea-d31c-45f4-bd8a-66ee7cfb916d');
ga('pacontentapi.set', 'dimension3', 'paservice:sport,paservice:sport:club-news,paservice:sport:football');
ga('pacontentapi.set', 'dimension6', 'story');
ga('pacontentapi.set', 'dimension7', 'composite');
ga('pacontentapi.set', 'dimension8', null);
ga('pacontentapi.set', 'dimension9', 'sport:football');
ga('pacontentapi.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'Doran decides quarter-final as Inverness dump out Dundee United'});