Kilmarnock survived a late onslaught by St Johnstone to book their place in Mondays’s Scottish Cup fifth round draw.
Craig Slater’s terrific free kick gave Killie the lead after just six minutes.
Josh Magennis proved to be a handful and had a couple of decent efforts as Killie threatened to extend their lead in a first half which they controlled.
Saints improved after the break and thought they had rescued a replay in a dramatic finale which saw Jamie Macdonald pull off a triple stop to deny Cummins, Mackay and Sutton.
McHattie then cleared off the line in the dying seconds. “If there’s a better goalkeeper in the Premier League I haven’t seen him,” said Killie boss Locke.
“I think we probably deserved to win.”
Saints boss Wright lamented: “That piece of brilliance has kept them in the Cup.”
Elsewhere Annan Athletic produced the shock of the round beating Premiership side Hamilton Accies 4-1 at Galabank.
Motherwell thrashed Highland league opposition Cove Rangers 5-0 at Fir Park, Dundee United narrowly scraped through against Airdrieonians, 10-man Linlithgow Rose produced a terrific fightback to earn a reply at Forfar and Stirling Albion held Inverness CT.
Scottish Cup Fourth Round results
Linlithgow Rose 3-3 Forfar
Airdrieonains 0-1 Dundee United
Annan 4-1 Hamilton
Dumbarton 2-1 QOS
Dunfermline 2-2 Ross County
Livingston 0-1 Morton
Motherwell 5-0 Cove Rangers
Raith 0-2 Hibs
St Johnstone 0-1 Kilmarnock
Stirling 0-0 Inverness CT