The game looked to be heading into extra-time when referee John McKendrick ordered a Stevie May free-kick to be taken again for encroachment by Nacho Novo who was booked for his troubles.
May's second effort from 25 yards was spilled by Morton keeper Nicolas Caraux and McDonald pounced to bundle the ball over the line to send the visiting fans into raptures and the home supporters into rage.
There was some chaos after the final whistle with Ton manager Allan Moore raging at the officials.
The Greenock side went into the game bottom of the Championship and without a win since causing the surprise of the competition by knocking out Celtic in the last round and will feel aggrieved.
Perth midfielder David Wotherspoon hit the post with a free-kick with 16 minutes remaining but there was little between the teams for most of the game until McDonald sent the Perth men into tomorrow's draw.
Saints, who beat Championship leaders Hamilton Accies in the last round, showed one change to their starting line-up as Stopper Frazer Wright returned from suspension to take over from Tom Scobbie who started on the bench.
The Greenock side had former Rangers favourite Novo in attack, backed from wide by Dougie Imrie who scored the winner against Celtic in the previous round.
However, the tepid start to the match belied its importance.
In the sixth minute an Imrie free-kick from the right was met by the head of Morton skipper Mark McLaughlin but Saints keeper Alan Mannus saved with some ease.
The Perth men took their time to work their way into the match and their first effort on goal came when Wotherspoon drilled a shot from just outside the box inches wide of the target.
Midway through the first half, with neither side gaining control, Imrie tried his luck with a speculative shot from 35 yards but although he found the power, the ball flew wide of the target with another drive in the 32nd minute speeding straight to Mannus.
Morton were forced into a substitution in the 36th minute, defender Marc Fitzpatrick limping off to be replaced by Jonathan Page.
Moments later, Saints striker Nigel Hasselbaink took a pass from Chris Millar 10 yards from goal, turned and drove into the side netting, fooling the visiting fans who thought he had scored.
Scobbie replaced Wright for the start of the second half, the Perth defender having failed to shrug off a knock picked up early in the match.
Morton were still giving as good as they were getting but neither side looked inventive enough to fashion a clear-cut chance.
As early as the hour mark, extra-time and even penalties looked a distinct possibility.
Stephen Stirling had replaced Joe McKee for Morton before Murray Davidson came on for Saints midfielder Patrick Cregg in the 62nd minute and the game at last came to life.
In the 74th minute, after May was adjudged to have been fouled 25 yards from goal by Tomas Peciar, Wotherspoon curled a free-kick off the outside of the post.
Moments later, Saints defender Brian Easton stretched to knock a Wotherspoon corner over the bar from six yards before Caraux made a good close-range save from Millar, who had been set up by May.
But the drama came right at the end when McDonald grabbed the winner.