Richard Brittain struck an injury-time equaliser to earn Livingston a replay against Second Division Alloa.
Michael Bolochoweckyj had headed the Wasps into the lead in the 66th minute from one of Jamie Stevenson's numerous excellent corners.
But Livi were saved by a superb strike from Brittain with just seconds of the match remaining.
Alloa caretaker-manager Gareth Evans will now take his side to Almondvale for another attempt at a cup shock.
The home side thought they had taken the lead after 16 minutes when, from a Jamie Stevenson corner, Fraser Forrest bundled the ball home - only to see the goal ruled out by referee Charlie Richmond for a push on McKenzie.
Paul Dalglish wasted an excellent opportunity to give his side the lead midway through the half when he was picked out brilliantly by Lambert but the Livi striker strangely opted to try a pass to Robert Snodgrass rather than have a shot at goal.
Alloa goalkeeper James Evans was called into action in the 42nd minute when he handled well from a Harald Pinxten header.
Three minutes after the interval, Iain Nicholson produced a fantastic left-wing cross and Stevenson hit the post with McKenzie rooted to the spot.
Just after the hour mark, the Wasps went close again when Stevenson's corner was headed towards the top corner by Ross Hamilton but Lambert was there to clear off the line.
It was from another Stevenson corner that the home side took the lead when Bolochoweckyj rose highest to head home in impressive fashion.
Lambert took matters into his own hands with a majestic 75th-minute free-kick, which beat Evans but hit the underside of the bar and bounced out.
Greg Strong looked poised to knock in the rebound from a yard out, but appeared to be nudged off the ball, although referee Richmond saw nothing amiss.
Wasps keeper Evans was called upon five minutes from time when he spread himself bravely to block a thunderous Snodgrass effort from close range as the home side desperately tried to hang on for a famous win.
Bolochoweckyj cleared off the line magnificently deep in injury time.
But, from the subsequent corner, Brittain arrowed a brilliant equaliser beyond Evans and into the bottom right-hand corner to save Livi's blushes.
Alloa: Evans, Bolochoweckjy, Mortimer, Forest, Nicolson,
Walker, McGeowen (Learmonth 77), Townsley, Sloan, Hamilton,
Stevenson (Graeme Brown 86).
Subs Not Used: McGlynn, Andy Brown, Quitongo.
Booked: Townsley, Hamilton.
Goal: Bolochoweckjy 66.
Livingston: McKenzie, Mackay, Pinxten, Strong, Tierney,
Dair (Hoolahan 62), Brittain, Lambert, Vincze,
Dalglish (Dorrans 70), Snodgrass.
Subs Not Used: Roy, McNamee, Walker.
Goal: Brittain 90.
Ref: C Richmond