South Africa were five wickets from victory as Sri Lanka finished the third day of the first Test on 103-5 in their second innings after being set a 516-run target on Friday.
The home side will have two days to chase down the remaining wickets with Sri Lanka still needing a daunting 413 more runs to win the Test at Kingsmead.
Captain Temba Bavuma and Tristan Stubbs scored centuries as the hosts built an imposing lead before declaring their second innings on 366-5 at tea.
Sri Lanka, dismissed for their lowest Test score of 42 in the first innings, saw Pathum Nissanka (23) and Angelo Mathews (25) get off to good starts before being dismissed but will again be disappointed with their batting effort.
Dinesh Chandimal (29) and captain Dhananjaya de Silva (0) will resume on Saturday.
Lanky bowler Marco Jansen, who took 7-13 in the first innings, bagged two more wickets, snagging veteran Mathews leg before wicket before the dangerous Kamindu Mendis edged a rising delivery behind to depart for 10.
Kagiso Rabada also took two wickets with Tony de Zorzi taking a sharp catch at short leg to get rid of Prabath Jayasuriya in the second last over of the day.
Earlier South Africa took full advantage of a pitch that went flat and docile after being lively on the first two days with Bavuma and Stubbs putting on 249 for the fourth wicket, taking the overnight score from 132-3 to 338 before Stubbs was bowled by Vishwa Fernando for 122.
Bavuma was out to the last ball before tea when he was trapped leg before wicket to Asitha Fernando for 113.
It was only Bavuma’s third century in his 60th Test. After developing a reputation for an inability to convert half centuries, this time he was a study in determination as South Africa manoeuvred into a match-winning position.
Bavuma, who has scored 23 test 50s, returned to the lineup from an elbow injury after missing the two-Test series win in Bangladesh last month.
Stubbs, who now has two test tons, was handed a lifeline when first slip Angelo Mathews spilled a nick from Stubbs off Vishwa Fernando when the South African was on 33.
He was also given out leg before wicket on 102 but successfully reviewed the umpire’s decision with the delivery from Lahiru Kumara outside the line and missing the stumps.
South Africa and Sri Lanka are both chasing victory in the two-Test series to stay on course for a place in next June’s World Test Championship final at Lord’s.
The second Test is in Gqeberha, starting next Thursday.