Rangana Herath bowled Hashim Amla with his drift and turn and Akila Dananjaya struck double blows when he dismissed South Africa captain Faf du Plessis (seven) and the scoreless Maharaj off successive deliveries.
Sri Lanka's formidable battery of tireless spinners bowled them to within five wickets of a 2-0 series sweep over South Africa as the tourists continued to struggle against the turning ball in the second and final test on Sunday.
The previous best bowling analysis by a South African since the country's return to test cricket in 1992 was Lance Klusener's eight for 64 against India in Calcutta in 1996.
Watch the Sri Lanka vs South Africa 2nd test Day 3 telecast on these channels.
No-one could accuse the South Africans of cleverness in their tactical thinking around this series.
Sri Lanka had resumed on day two on 277-9 and extended its first innings with a record 74-run, last-wicket stand.
Cape Town - Proteas opening batsman Dean Elgar admits that Sri Lanka have been the better team in the two-match Test series.
South Africa gave another deplorable display of batting against spin when they were shot out for 124 by tea replying to Sri Lanka's first innings total of 338. South Africa has not lost a series to Sri Lanka since 2006.
To say that the day belonged to Dananjaya would not be an understatement for before he wrecked the South African batting and frustrated their bowlers on the field by batting for almost two hours to score a career best 43 not out off 91 balls (7 fours).