On a night of high drama, Kilmarnock were on course to secure their first win over Aberdeen at Rugby Park since December 2011 following Mohamed El Makrini's spectacular first-half overhead kick only for that to be cancelled out by Andrew Considine with two minutes remaining.
In extra-time there was an extraordinary scoring spree as this pulsating cup tie ebbed and flowed.
And stoppage time of extra-time, the unfortunate Connor Johnson scored an own goal from a Considine cross to seal the win for Aberdeen and set up a meeting with St Mirren in the last eight.
Kilmarnock dominated possession in the first half and a moment of magic from El Makrini broke the deadlock two minutes before the interval.
Chris Burke delivered an inviting cross from the right flank which the Aberdeen defence failed to deal with and El Makrini produced an overhead kick.
It might not have been the cleanest of strikes but it was enough to leave Aberdeen goalkeeper Joe Lewis floundering.
Aberdeen manager Derek McInnes was clearly not impressed by his side's first-half display as he made a triple change at the break with Shay Logan, Cosgrove and Dean Campbell coming on for Craig Bryson, Connor McLennan and Dylan McGeouch.
Brophy had a wonderful opportunity to double their lead after 63 minutes but fired straight at Lewis when clean through on goal.
Then in the 80th minute Brophy went close again with a curling shot from an Stephen O'Donnell cross but it went just the wrong side of the post.
Kilmarnock paid the price for not getting a second goal to kill off the tie as Aberdeen equalised through Considine in the 88th minute.
McGinn whipped in a free-kick from the right corner of the penalty box and Considine glanced a header into the bottom corner.
Aberdeen almost won it in stoppage-time when Considine diverted a powerful header against the crossbar.
However, two minutes into extra-time Aberdeen did go ahead. Curtis Main was denied by Kilmarnock goalkeeper Laurentiu Branescu but the ball then spun into the path of the unmarked Kennedy and he headed into the unguarded net.
Brophy then made amends for the chances he had spurned as he drew Kilmarnock level with a stunning free-kick. From 25-yards out, he curled the set-piece over Aberdeen's wall and beyond Lewis.
Moments later he hit the post with another curling effort from outside the box.
With just three minutes of extra-time remaining, Kilmarnock reclaimed the lead when substitute Ross Millen's cross was diverted goalwards by Aberdeen defender Michael Devlin but Lewis pulled off a reaction save, only for Kabamba to bundle home the rebound.
Aberdeen were presented with the chance to draw level a minute later when Stuart Findlay bundled over Lewis Ferguson inside the box and Cosgrove calmly slotted past Branescu from the penalty spot.
However, the scoring was not finished as Aberdeen clinched victory in stoppage time when Killie substitute Johnson inadvertently diverted a Considine cross beyond his goalkeeper to the delight of the visiting support.