Rangana Herath was batting on 12 with Suranga Lakmal (six) dismissed off the last ball of the day.
Sri Lanka trail South Africa by 172 runs with one wicket in hand.