Cape Town: England's openers came through the last half an hour unscathed after South Africa declared on 627 for seven and the second test was heading for a draw on Tuesday.
South Africa captain Hashim Amla made a double century and Temba Bavuma struck his maiden test hundred on the fourth day to take South Africa to within just two runs of England's mammoth first-innings total.
England reached the close on 16 for no wicket with an 18-run lead after Alastair Cook and Alex Hales negotiated six overs as South Africa sought to turn the pressure back on the tourists after dragging themselves back into the match.
Amla scored 201 and the diminutive Bavuma 102 not out as South Africa forced England to bowl 211 overs in searing heat at Newlands.
It made the prospect of a result highly unlikely with just one day to play, but the hosts' morale should be lifted after a 241-run loss in the first test in Durban and a series of mediocre results in 2015.
Amla, whose captaincy had been criticised, was the cornerstone of the fightback, spending almost 12 hours at the crease and facing 477 balls. He was dropped twice on Monday but showed impressive concentration.
South Africa were still under pressure at the beginning of the fourth day at 353 for three but it was only after the third new ball was taken after lunch that England made a breakthrough when Stuart Broad bowled Amla for 201.
Faf du Plessis went three balls later after making 86 off 216 balls, edging a low catch to Ben Stokes at third slip off the bowling of James Anderson.
Quinton de Kock fell for a trap set for him as he pulled a ball from Broad straight to Anderson at short square leg.
Bavuma played an array of attacking strokes to race to his fifty off 52 deliveries before tea and brought up his century, which included 16 fours, to earn a standing ovation from the crowd.
His pulls and hooks made for an entertaining innings, although he was dropped by wicketkeeper Jonny Bairstow and got away with several thick edges.
Chris Morris played a good supporting role in his first test and was looking odds-on for a ton of his own before driving on the up and being caught by Root at short extra over off Steven Finn for 69.