Left-arm spinner Rangana Herath took 4-49 as South Africa crashed to their lowest total against Sri Lanka. The tourists were earlier bowled out for 338. Thilan Samaraweera made a century and Marchant de Lange took seven wickets on his debut.
De Lange's figures of 7-81 were the best recorded by any bowler in test matches in 2011.
Samaraweera and Herath frustrated the South African bowlers at the start of the day, adding 46 to the overnight total of 7-289, with Samaraweera batting watchfully to reach 102, his 13th Test century, off 265 balls.
After Samaraweera reached his hundred, Herath top-edged a slog against De Lange and was caught by wicketkeeper Mark Boucher for 30. The tall, strongly built De Lange wrapped up the innings, having Welegedara caught at short leg fending off a vicious bouncer before Samaraweera was caught at deep cover.
South Africa reached 0-22 without Graeme Smith and Jacques Rudolph looking in any trouble before Rudolph played a loose hook against Thisara Perera and was caught at long leg by a diving Welegedara.
Welegedara and Herath kept the pressure on the batsmen and it needed some bold hitting from tail-enders Dale Steyn and Imran Tahir to allow South Africa to avoid the follow on.
- AAP