The Gable Endies travelled north on the back of a fine win away to Ayr United in the last round, looking for an upset against a Dons team who have won nine and drawn one of their ten matches so far this season.
And the visitors almost snatched the lead on three minutes, Tom Ritchie being forced into a fine save from Stockton, the keeper keeping out the front man's shot with his feet.
On twelve minutes, Aberdeen took the lead, Barron's corner being flicked on at the near post for Kieran Shanks to head home from close range. And it was nearly two five minutes later. A fabulous ball from Barron picked out Ramsay whose cross just evaded the inrushing Shanks.
Aberdeen were dominating possession and playing some tidy football despite the blustery, cold and wet conditions but were finding the visitors defence difficult to breach. Montrose were dangerous on the break and both Stockton and Cammy McCormack had decent efforts on goal as they pushed for an equaliser.
Six minutes into the second half, Montrose winger Innes saw a shot deflected just wide and from the resulting corner the ball broke to Cammy McCormack 30 yards out and his fierce drive took a nick off a defender on its way past Ritchie to give the Angus side an equaliser.
The goal lofted the visitors and they enjoyed a good spell with Stockton again coming close. Michael Ruth tested Matthews just before the hour mark but Montrose were dealing well with everything the Dons threw at them.
On 76 minutes, Montrose took the lead when Dalglish's swirling free kick from the right found its way into the net, possibly assisted by the wind.
The Dons responded quickly with Ruth finding space in the box three minutes later to wheel and fire a left-footed shot past Matthews to tie things up at two apiece.
As the game went into stoppage time it looked as though extra time would be needed to separate the teams, but skipper Connor Barron had other ideas. First, he curled a delightful twenty yard effort past the keeper then, after Lyall Booth had been fouled in the area, he did his usual immaculate job from the spot to wrap up a victory for which the team had to work extremely hard.
Montrose deserve great credit for pushing Aberdeen all the way in a very entertaining tussle but the Dons march on and now await the quarter final draw.