Inverness Caley Thistle came from behind to book a lucrative Scottish Cup fifth-round tie against Celtic.

But it was another error from goalkeeper Chris Smith that brought Inverness back into the game.

Andrew Barrowman headed the opener five minutes before half time.

But Smith's poor clearance gifted Jonny Tuffey a 54th-minute tap-in, substitute Shinnie fired Inverness into the lead three minutes into extra time and Greg Tansey drilled in their third.

Dunfermline had home advantage but went into the game looking for their first win this season at East End Park, having not beaten Inverness in their last eight meetings and with Smith's howler in their previous meeting fresh in their minds.

There had to be a winner this time after the three draws in three games between the sides this term, but it was perhaps little surprise that it took extra time to separate them.

Shinnie's introduction appeared to turn the game in Caley Thistle's favour

Inverness were the ones to go into the game full of confidence, Saturday's 1-0 win away to Motherwell having stretched their unbeaten run to four games following a recent improvement in form that has lifted them off the bottom of the Scottish Premier League.

They have been replaced there by a Dunfermline side who lost to relegation rivals Hibernian on Saturday and whose only win in 18 games came on 5 November.

But it was the Pars who started on the front foot, with Barrowman's swift shot on the turn looping a few yards wide from 18 yards within 20 seconds.

The striker should have opened the scoring a couple of minutes later when he took David Graham's pass over the visiting defence in his stride, but his weakly struck low shot from just inside the penalty box was palmed clear by goalkeeper Jonny Tuffey.

Tuffey was given his chance with Ryan Esson suffering a strain, while Ross Tokely replaced the suspended Kenny Gillet and Richie Foran was fit to come in for Nick Ross, but most eyes were on the Northern Irishman's opposite number.

Smith was back in goal for the first time since his awful mistake handed Jonny Hayes the stoppage-time equaliser that secured Caley Thistle the replay.

With on-loan Iain Turner ineligible and Paul Gallacher injured, the obviously nervous Smith's every touch was greeted with trepidation from the home support and expectation from the visitors.

However, it took Inverness 26 minutes to test Smith and a Dunfermline defence in which Kevin Rutkiewicz was making his first appearance since August in place of John Potter.

Even then, Tansey's shot from 10 yards was blocked before it reached the goalkeeper and it was the returning central defender who helped engineer the Pars' breakthrough.

Rutkiewicz sent Joe Cardle down the left and, when the winger turned back inside his marker, his cross found Barrowman at the back post to head home from five yards.

Inverness manager Terry Butcher went for broke, bringing on Shinnie for midfielder Lee Cox at half time and the forward had an immediate impact, sending wide a drive and setting up Billy Mckay from a shot that stung Smith's fingers.

The tide was turning, but it was another Pars howler that handed Caley Thistle the equaliser when Smith tried to clear Alex Keddie's loose backheader from an innocuous punt upfield, the ball rebounded off Rutkiewicz towards his own goal and Hayes tapped into the unguarded net.

Inverness were looking the more determined, exemplified by Hayes and Foran both being booked when the team-mates clashed angrily after 74 minutes.

Smith redeemed himself slightly by turning a powerful 20-yard drive from Shinnie over the crossbar.

Dunfermline survived the pressure and Ryan Thomson, who had started ahead of the experienced Gary Mason, powered into the penalty box only for Tuffey to save the midfielder's weak effort at the second attempt.

The home side paid for that and for failing to close down Shinnie as, three minutes into extra-time, the substitute fired a drive off the inside of the far post from 18 yards.

Tansey made sure of Caley Thistle's place in the next round when he gathered a pass from fellow sub Ross and fired into the corner from just outside the box for a deserved win but one that had another Dunfermline error as its catalyst.

Gregory Tade is caught offside. John Potter restarts play with the free kick.

100:31

Inswinging corner taken by Joe Cardle.

97:24

Free kick awarded for a foul by Johnny Hayes on Paul Willis. Chris Smith restarts play with the free kick.

95:26

Shot by Richie Foran from outside the box goes over the target.

92:20

The assist for the goal came from Gregory Tade.

92:20 Goal scored

Goal! - Andrew Shinnie - Dunf'mline 1 - 2 Inverness Andrew Shinnie finds the back of the net with a goal from the edge of the penalty box to the top left corner of the goal. Dunfermline 1-2 Inverness CT.

90:00 +4:21

Normal time is of over and the game goes into extra time.

89:58

Ross Tokely takes the free kick.

89:58 Substitution

Substitution David Proctor on for Roman Golobart.

89:58

Roman Golobart fouled by Paul Willis, the ref awards a free kick.

86:31

Corner taken by Joe Cardle, Ross Tokely makes a clearance.

85:52

Chris Smith restarts play with the free kick.

85:52 Substitution

Substitution Billy McKay leaves the field to be replaced by Nick Ross.

85:52

Free kick awarded for an unfair challenge on Paul Willis by Graeme Shinnie.

84:04

Joe Cardle takes the inswinging corner, clearance by Gregory Tade.

83:18

Effort from deep inside the area by Andy Kirk misses to the left of the target.