Ryan Wallace and Jordan Moore both scored twice as Dunfermline held off a late Elgin fightback to record a 5-3 victory in the Scottish Cup third round.
Jamie Duff's 16th-minute looping header gave the League Two side the lead but Wallace converted Ross Millen's cut-back three minutes later to level before drilling in from the edge of the area to give his side a slender lead at the interval.
Second-half substitute Moore took eight minutes to open his account, tucking in from the spot after David Niven had brought down the on-loan striker in the area.
Moore added a fourth a minute later, latching on to a poor backpass to slot home and Alex Whittle thumped in from the edge of the box to make it five.
But Dennis Wyness's bundled finish and Dachi Khutsishvili's header set up a nervy last five minutes.