In a tight opening to the match, it was Rangers who created two difficult chances as Kenny Miller sent an acrobatic volley over, before Kris Boyd's low strike was kept out by Alan Mannus at the end of a counter-attack from the hosts.
A goal before the break appeared to be unlucky, with neither side able to take complete control of the contest throughout the first half.
St Johnstone struggled to attack in numbers for long spells, but should have taken a lead into the interval when Lee Croft's inviting cross found Frazer Wright, who somehow managed to head over from close range.
Despite being asked to do very little in the first half, Steve Simonsen made a vital contribution after the break to keep out a powerful header from Brian Graham, before being forced off with an injury he suffered colliding with the post in the process of making the save.
Rangers then twice went close with headers from Boyd and Lee McCulloch, with neither player able to hit the target after finding space inside the box.
The game opened up in the latter stages, and the visitors missed a great chance to take a crucial lead when Jon Daly headed against the post moments after being sent on as a substitute.
St Johnstone would be punished for the miss as Rangers secured their spot in the last four through Macleod, who headed home from a Frazer Aird cross to snatch the victory for his side in the 86th minute.