The first Test between New Zealand and South Africa will go into a third day after the visitors rallied with both bat and ball at Newlands.
AB de Villiers' busy half-century allowed South Africa to declare at 347 for 8, a lead of 302, but the hosts' grip on the match loosened in the afternoon as the runs flowed, catches were dropped and New Zealand battled gamely in the sunshine.
They had reached 169 for 4 by the close, the deficit reduced to 133, with Brendon McCullum contributing a two-paced fifty and Dean Brownlie - who had been on a pair - a brave, unbeaten 69.
So calamitous had New Zealand's first innings been that there appeared every chance this Test could be wrapped up by the second evening, and the signs were ominous when Martin Guptill flapped Dale Steyn's sixth delivery in the second dig straight to Hashim Amla at midwicket.
Steyn and Vernon Philander were close to unplayable in an opening spell that bristled with intensity, but McCullum and Williamson stopped the rot with a partnership of limpet-like tenacity, crawling along at under two runs an over without a shot in sight.
Williamson, in particular, was helped by a little luck with the Decision Review System, but their obdurate stand was snapped when his luck, and admirable concentration, finally abandoned him. Jacques Kallis was introduced a few minutes before Tea and, wafting lazily at a ball he could easily have left, Williamson presented an easy catch behind the stumps and a timely wicket for South Africa.
Again, it appeared New Zealand might fold meekly but instead they went on the counterattack. Brownlie opened the final session with three consecutive boundaries off the miserly Philander, while McCullum switched gears and helped to up the sluggish run-rate with a succession of powerful strokes on either side of the wicket.
The frustration felt by South Africa's toiling bowlers increased significantly when, in the course of 12 chaotic deliveries, three catches were put down behind the wicket and both batsmen were gifted lives. In between the drops a 50-run third-wicket stand, from just 45 deliveries, was brought up and when a second chance went down off Steyn, the livid fast bowler marched out of the attack.
The breakthrough eventually came through spin, or rather lack thereof as Robin Peterson speared one in at McCullum's pads to trap him lbw for 51. Having added 89 from 81 balls with his captain, Brownlie barely slowed down and reached a 44-ball half-century in the 35th over of the innings.
He appeared to have found an able partner in Daniel Flynn and the pair added 37 runs, before Kallis once again broke the stand, having the left-hander caught behind with the final ball of the fourth over of his second spell.
South Africa's quicks surged at the thought of a few more wickets before the close, with Brownlie in particular bearing the brunt of a short-pitched assault from Steyn. He stood firm, however, ensuring that New Zealand will live to fight another day.
Indeed, with 136 runs added for the loss of only two wickets in the final session of the day, New Zealand can take plenty of heart from their improved performance. Though the likelihood of a South African victory is still strong, the hosts had certainly been in a stronger position at the start of the day than at the end of it.
South Africa began the day in the healthy position of 252 for 3 but Alviro Petersen, sitting on an unbeaten ton overnight, could add only three runs to his total before he played on to the first ball of Trent Boult's spell.
The cloudy, blustery conditions in the first hour emboldened New Zealand's seam quartet, and neither Faf du Plessis nor the battling Dean Elgar lasted long. There was an ironic cheer from the stands when Elgar nudged the ball off his hips to break his duck as a Test batsman but he could not find the confidence to settle and his technique was found particularly wanting outside off stump.
His scratchy effort was finally ended by Boult, who found his outside edge with a lifter moments before lunch. Nevertheless, he'd done enough to add 54 with de Villiers, who created angles and picked gaps almost at will, striking seven fours before reaching an 88-ball half-century.
De Villiers' shot-making grew a little fidgety after lunch, suggesting that a declaration might not be far away, but he paid the price for his over-inventiveness when he walked across to Chris Martin and had his exposed leg stump pegged back for 67.
Graeme Smith finally called his men in when Peterson swung across the line to give Martin his third shortly aftewards. With the lead stretched beyond 300, and the cracks in the pitch widening enough to cause significant variations in bounce, another New Zealand capitulation loomed. In the event, Brownlie and McCullum ensured that would not be the case.