Dundee progressed to the last eight of the Scottish Cup 3-0 but were given a thorough examination by the highly-impressive Peterhead.
The top-flight side created a paucity of chances but a contentious penalty, converted by Charlie Adam, a goal on the counter from Niall McGinn and a late Josh Mulligan strike sent them through.
The Blue Toon ought to have had a spot-kick of their own, with referee David Munro ignoring a clear foul on Ryan Duncan, and Dundee goalkeeper Ian Lawlor required to make several key saves.
It is the Dark Blues who advance, though, to the quarter-finals.
Peterhead made four changes from the 1-0 defeat to Alloa Athletic, with the cup-tied Jack Brown and Rico Quitongo dropping out, David Wilson absent and Russell McLean on the bench. In came Ryan Conroy, Scott Brown, Hamish Ritchie and Grant Savoury.
The two sides had met five times previously, all in the League Cup, with the Blue Toon’s only victory coming in 2016.
Manager Jim McInally had urged his side not to shrink in the spotlight of the game and the opening exchanges saw the players carry out those orders.
Dundee goalkeeper Ian Lawlor was tested by efforts from Scott Brown and Niah Payne, while Ryan Duncan had a shot blocked by ex-Peterhead loanee Cammy Kerr.
A short-corner routine forced Lawlor into a low stop at his near post from Ritchie as the hosts continued their impressive start to the game.
Dundee’s offering was pretty tame, with forwards Danny Mullen and McGinn rarely seeing the ball in threatening positions and their midfield being bypassed by balls out from the back.
They were more than fortunate, then, to find themselves ahead at the interval. McGinn had played the ball through to Paul McMullan and after he took a heavy touch, he ran into goalkeeper Brett Long.
Referee David Munro pointed straight to the spot, despite protests from Peterhead players. Adam sent Long the wrong way from 12 yards.
McInally’s men, to their credit, did not wallow. Persistence from Payne allowed him to dig out a cross from the right and pick out Ritchie, whose shot came off the inside of the post and somehow did not cross the line.
They had a firm case for a penalty of their own before half-time as Duncan nipped in to get the ball ahead of Lawlor, before being bundled to the floor by the stopper. Munro was unmoved.
Fortune continued to frown on Peterhead at the start of the second half too, with a superb free-kick from the lively Grant Savoury being turned away spectacularly by Lawlor.
Dundee duly punished them, with a long diagonal from Adam picking out McGinn, who chopped inside McDonald and slotted the ball past Long.
The simple answer would have been a touch of genuine quality from an experienced player had put the tie beyond Peterhead.
But they were comfortably the better side against Premiership opposition at Balmoor, fashioning more chances and looking more likely to find the net.
McInally and Peterhead did not change their approach even after the second goal, with strikers Russell McLean and Derek Lyle raised from the bench to try grab a consolation.
McLean got his header on a looping free-kick, which Lawlor was able to cling on to, and Duncan continued to give Kerr a chasing down the right-hand side.
Mulligan, who was on loan at Peterhead earlier this season, added a late third with a well-taken strike into the far corner.
The hope for McInally now will be that Peterhead can transfer such a performance into their league form.
While the ambition among the players may have been to challenge for play-off places – that prospect has not gone yet – they are still too close to the opposite end of the table for comfort.
But in front of a national TV audience, they showed a little bit of what this youthful side is about. Dundee certainly should not forget that in a hurry.