Ayr United 1 St. Johnstone 2
The Second Division side had looked set for penalty kicks after a brave fight in horrific conditions at Somerset Park.
They had a mountain to climb when they fell behind after only five minutes when Trinidad striker Jason Scotland drove a low 20-yard free-kick into the bottom corner of the net.
But United fought back and pinned their First Division visitors into their own half without reward.
They finally broke through midway through the second half when former St Johnstone man Ryan Stevenson fired home a cracking half-volley from the edge of the box.
Saints had chances to win the tie with the gale-force wind behind them but the game went into extra-time.
However, just as penalties looked certain McDonald fired home from 30 yards with a cruel wind-assisted winner.