South Africa captain Hashim Amla remained unbeaten after his 22nd test hundred but off-spinner Dilruwan Perera's career best figures gave Sri Lanka a big first innings lead at the end of the third day of the second Test.
South Africa were dismissed for 282 in reply to Sri Lanka's first innings total of 421. At stumps Sri Lanka were 11 without loss with Upul Tharanga on six and Kaushal Silva on five, with a lead of 150.
Amla batted through the South Africa innings to remain not out on 139, having batted for eight hours during which he faced 382 balls and hit 12 fours.
In the morning, Perera struck twice in one over to dent South Africa's hopes of getting close to Sri Lanka's first
Overnight pair Amla and AB de Villiers took South Africa to 143-3 in the first hour of play, adding 45 fairly untroubled runs, with the former completing his 28th test fifty off 140 balls.
Perera struck twice in his 19th over by getting rid of De Villiers for 37 and the dangerous Quinton de Kock for a duck.
De Villiers' dismissal ended a stubborn fourth-wicket partnership of 79 with Amla but De Kock lasted just two balls before he was beaten by the flight and clean bowled by Perera.
Valuable Steyn wicket
Steyn was eventually dismissed for 30 but by then he had eaten up valuable time which Sri Lanka can ill-afford if they are to win the test and draw the series.
Herath took Steyn's wicket when the batsman holed out to Kumar Sangakkara at long off after spending 75 minutes and 71 balls in the middle.
The left-arm spinner also accounted for Imran Tahir (15) having him caught at wide mid-off to finish with figures of four for 71.
Perera picked up his second five-wicket haul of his career when he had Mornie Morkel caught at forward short leg for a duck to end the South African innings.
Perera also bowled Vernon Philander through the gate for nine. JP Duminy, who took 58 balls to score his three runs before being drawn outside his crease by Herath, was out stumped.
South Africa appeared intent on occupying the crease for as long as possible and Amla was helping them do just that with the second session producing just 71 in 29 overs.