Sri Lanka captain Mahela Jayawardene hit the fourth highest score of 374 and shared a world record stand of 624 with Kumar Sangakkara as the hosts piled up a mammoth 756-5 declared in their first innings.
The Proteas, who conceded a massive lead of 587 after being shot out for 169 on the opening day, ended the day at 43-0 in their second knock with Jacques Rudolph on 24 and Andrew Hall on 13.
South Africa must bat out the remaining two days to save the game with seasoned opener Herschelle Gibbs unable to bat till the fall of the fifth wicket after being off the field with a stomach bug.
"It's not going to be easy to save the game, but it's not over yet," said South African coach Mickey Arthur. "They still have to take 10 wickets and the boys are determined not to make it easy for them.
"The two Sri Lankans batted as if nothing bothered them, so maybe we can take a lesson from that and believe the wicket is still good for batting.
"We did not lose a wicket before close and hopefully the boys can go on the same way. The trick is to play it session by session."
Jayawardene and Sangakkara, who came together on Thursday evening with their team on a precarious 14-2, destroyed the South African attack in the best ever partnership in the history of Test cricket.
The third-wicket pair surpassed the previous best of 576 for the second wicket by fellow-Sri Lankans Sanath Jayasuriya and Roshan Mahanama against India at the Premadasa stadium here in 1997.
Left-handed Sangakkara fell for 287, caught behind chasing a wide ball from Andrew Hall, but Jayawardene batted on to surpass Jayasuriya's Sri Lankan record of 340.
Jayawardene crossed West Indian Garfield Sobers' 365 not out and was one run away from equalling Brian Lara's 375 against England in 1994 when he was bowled by an express Andre Nel delivery.
Some 4,000 home fans fell silent, having expected Jayawardene to cross the three remaining milestones: Lara's 375, Matthew Hayden's 380 and Lara's world record score of 400 not out.
Jayawarden, 29, said the individual record never crossed his mind since he and Sangakkara were more concerned about how the match would turn out.
"It was more important for us to put runs on the board as best we could," the Sri Lankan captain said. "We still have a Test to win and we know there is a lot of hard work ahead of us in this game over the next two days.
"South Africa are great fighters. We have seen it in the past and know that they will do what they can to save this game."
Jayawardene hit 43 boundaries and a six during his 15th three-figure knock as the depleted South Africans wilted in the heat.
There was little the South Africans could do to stop the rampaging Jayawardene and Sangakkara in good batting conditions.
Left-arm spinner Nicky Boje bore the brunt of the assault, conceding 221 runs in 65 unsuccessful overs. Dale Steyn took 3-129 in 26 overs and pace spearhead Makhaya Ntini went for 0-97 in 31 overs.
It was the best display by two batsmen in a Test innings since Sobers made the unbeaten 365 and Conrad Hunte 260 for the West Indies against Pakistan in Kingston in 1957-58.