A controversial late goal by Gary McDonald secured St Johnstone a place in the Scottish League Cup semi-finals at the expense of Greenock Morton.
The match appeared to be heading for extra-time when Saints won a free-kick.
Stevie May's shot was blocked but referee John McKendrick ordered the set-piece to be retaken, much to Morton's frustration.
The second effort was spilled by goalkeeper Nicolas Caraux and McDonald netted from the resulting loose ball.
St Johnstone join Aberdeen, Hearts and Inverness Caledonian Thistle in Thursday's semi-final draw.
Scottish Championship side Morton were hoping to claim another Premiership scalp after their shock win at Celtic Park in the previous round.
McDonald scored in the fifth minute of injury-time
And the hosts's captain Mark McLaughlin had an early header saved by goalkeeper Alan Mannus.
A speculative long-range effort from Dougie Imrie flew wide of the visitors's goal and the midfielder tested Mannus with another drive moments later.
Nigel Hasselbaink fired into the side netting as Saints tried to force an opener before the break.
With chances few and far between in the second half, St Johnstone won a free-kick 25 yards out that David Wotherspoon fired against the outside of the post.
Brian Easton then directed a Wotherspoon corner over Caraux's goal.
As the match entered injury-time, Saints won another free-kick and May's effort came back off Nacho Novo, only for referee McKendrick to order the retake.
Novo was booked for encroachment and May's second effort was not held by Caraux, allowing McDonald to pounce and secure victory for the Perth side.
St Johnstone boss Tommy Wright: "
We had the character to keep going but you also have to give Morton credit. We showed hunger and desire to get a winner. When Stevie May is over a free-kick then anything can happen. It's come off the keeper and we've followed it in - Gary McDonald's stuck it in.
"We're happy to come through the tie and have a big game to look forward to. To get a goal that late, maybe fortune's favouring us."
- 23 Caraux
- 12 Reid
- 03 Fitzpatrick (Page - 36' )
- 18 Habai Booked
- 06 McLaughlin
- 04 Peciar
- 09 Wallace
- 21 Bachirou
- 20 Gómez Novo Booked
- 07 McKee Booked (Stirling - 58' )
- 08 Imrie Booked
- 01 Gaston
- 05 Page
- 10 Campbell
- 16 Stirling
- 48 Cham
- 01 Mannus
- 19 Miller
- 24 Easton Booked
- 08 McDonald
- 02 Mackay
- 05 Wright (Scobbie - 46' )
- 07 Millar
- 04 Cregg (Davidson - 64' )
- 17 May
- 11 Hasselbaink Booked (Fallon - 79' )
- 10 Wotherspoon
- 03 Scobbie
- 14 Edwards
- 15 Banks
- 18 Davidson
- 27 Fallon
Ref: John McKendrick