The First Division side held Steve Lomas' men at bay for 45 minutes but the Perth outfit slowly eroded their hosts' resolve after the break.
David McCracken stole in to open the scoring in the 54th minute and the Blue Brazil soon contrived to offer the SPL side a second goal.
Steven MacLean obliged from the penalty spot when Thomas Flynn fouled Murray Davidson in the 76th minute, before Gregory Tade ensured the Saints' safe passage to Paisley with a close-range finish three minutes from time.
Hamilton will play Dunfermline in the last 16 after overcoming fellow First Division outfit Dumbarton 3-1 at the Bet Butler Stadium.
Alister Crawford put the visitors ahead with a stunning effort in the 24th minute, before Michael Devlin doubled Hamilton's advantage four minutes before the break.
Dumbarton's players rallied after the interval, though, setting up Chris Turner to head home from close range in the 57th minute, but Accies substitute Grant Gillespie struck from deep inside the penalty area with 75 minutes on the clock.
The Sons' chances of success suffered a further setback when Turner saw red three minutes later and Hamilton progressed to the next round.
Peter Weatherson scored a hat-trick as Morton earned a trip to Dundee with a resounding 6-0 win over Highland Football League hopefuls Turriff United.
It took 37 minutes for Morton to open the scoring through Weatherson but the First Division outfit would not look back.
Michael Tidser registered his first goal from the penalty spot in first-half stoppage time following Ross Anderson's foul, adding a second from long range in the 63rd minute.
Morton were out of sight when substitute Peter MacDonald found the back of the net in the 77th minute, Weatherson quickly laying claim to the matchball with two goals in the last 10 minutes.