It took the home side just 38 seconds to rattle the woodwork as Hearts exploded from the blocks.
Uche Ikpeazu took advantage of some sleepy Dons defending to hare through on goal – but his curling shot hit the under-side of the bar and he could only head the rebound wide.
Hearts' bright start counted for nothing when Berra hauled down Ryan Hedges as the winger tried to control a bouncing ball inside the penalty area. Referee Kevin Clancy pointed to the spot and Cosgrove sent Pereira the wrong way.
Aberdeen's lead lasted just 12 minutes as more lamentable defending allowed the Jambos to restore parity. Devlin inexplicably failed to cut out a hopeful delivery into the danger area, affording MacLean all the time and space in the world to slot home from 10 yards.
A breathless first period saw Hearts again fall behind to due to an avoidable error as Damour tripped James Wilson inside the box as the striker sought to latch onto a Hedges pass. Again, Clancy awarded the penalty and Cosgrove made no mistake.
The visitors came close to doubling their advantage after the break when Greg Leigh fizzed a low shot inches wide of the post and, with the away fans serenading Craig Levein with a rendition of 'sacked in the morning', Hearts appeared to be running out of ideas.
However, Halkett popped up two minutes into added time to head home a sensational inswinging cross from winger Jake Mulraney and send the game into extra-time.
McGinn was presented with a glorious opportunity to settle the contest during a fraught period of extra-time when he met a Jon Gallagher cross, but the Northern Ireland international saw his header came back off the base of the post.
Having held on for penalties, it was the Jambos – in sharp contrast to Aberdeen – who held their nerve with three superbly dispatched efforts.