Vernon Philander recorded his 11th five-for and Stephen Cook scored a century as South Africa took command of the first Test against Sri Lanka on day three in Port Elizabeth.
Sri Lanka resumed on 181-7 but their hopes of closing in on the Proteas' first-innings score of 286 were immediately dented by Philander.
The quick accounted for Dhananjaya de Silva (43) and Suranga Lakmal (4) in the first over of the day before finishing with figures of 5-45 as Sri Lanka were all out for 205.
Cook (117) propelled the Proteas forwards with his third Test ton, building impressive partnerships with Dean Elgar (52) and Hashim Amla (48 off 53 balls), who became the 10,000th player to be dismissed leg before wicket when he was trapped by Nuwan Pradeep (1-65).
After a costly drop from Dhananjaya, Dushmantha Chameera (1-63) finally brought Cook's knock to an end and the hosts appeared to hit a stumbling block.
However, Faf du Plessis (41) and Quinton de Kock's (42) unbeaten 74-run partnership for the sixth wicket enabled the Proteas to reach stumps at 351-5 for a 432-run lead.
-- ICC (@ICC) December 28, 2016
Philander allowed Sri Lanka no time to settle and tempted Dhananjaya into edging back to wicketkeeper De Kock first ball.
Kyle Abbott (3-63) took the catch to remove Lakmal off Philander and added a wicket of his own when Chameera (19) directed an edge straight to Amla at slip, sending the Proteas back in with an 81-run lead to build on.
Elgar reached 1,500 Test runs before the covers came out amid bad weather 11 overs in, and, despite another delay, he and Cook were unhindered as they mounted a 116-run stand for the first wicket.
Chameera and Pradeep were both sent to the boundary twice in one over by Cook, but he received a reprieve when Dhananjaya put him down at gully on 62.
After Elgar fell to Lakmal, having notched his fourth Test fifty, Cook's pace slowed until he brought up his hundred off 151 balls by following a four off Chameera with a pair of runs from a shot to long leg.
Amla found the ropes five times but his aggressive knock ended when he was trapped lbw by Pradeep, and Cook followed soon after with a thin edge to wicketkeeper Dinesh Chandimal.
JP Duminy (25) and Temba Bavuma (8) were dismissed as Dhananjaya made headway, but Du Plessis and De Kock steadied the ship and kept the Proteas on top.
Du Plessis must now decide whether to declare overnight or mount an early surge on day four with victory in sight for the hosts.