Herschelle Gibbs put his poor recent form behind him to strike a dashing 92 and put South Africa in control of the second and final Test against Sri Lanka in Colombo.
Muttiah Muralitharan kept Sri Lanka in the hunt with four wickets, including Gibbs, but at 257 for seven at the close of day three the visitors are 297 ahead and in with a great chance of levelling the two-match series up at 1-1.
Gibbs excelled at the top of the order, scoring 11 fours and one six to help put the Proteas in the driving seat and with the dangerous Mark Boucher unbeaten on 28 South Africa will be confident of setting Sri Lanka a testing target.
South Africa, with Gibbs and Andrew Hall at the crease, were six for nought overnight and added a further 70 runs before Farveez Maharoof had Hall (32) caught by Prasanna Jayawardene off the shoulder of his bat.
Gibbs, who has been struggling of late, passing 20 just once in his last 11 innings, soon celebrated his 22nd Test fifty.
Despite his assured display, though, South Africa were rocked by two quick-fire runouts as first Jacques Rudolph (15) and then Hashim Amla (eight) both failed to make an impression. Chamara Kapugedera was responsible for both dismissals.
Muralitharan then had Gibbs caught by Sanath Jayasuriya, eight short of his century after a mistimed sweep.
That left Sri Lanka 201 behind with six wickets yet to take. It was a task Muralitharan took to with aplomb, tempting Ashwell Prince (17) into offering a return catch before snaring AB de Villiers (33) at short leg just three balls later.
Shaun Pollock became his fourth victim seven overs from the end when he dragged a long-hop straight to Upul Tharanga having scored 14.
It was a gutsy fightback from the spinner but with plenty of time left in the game and Boucher at the crease with Nicky Boje (five not out), the visiting team are favourites to push on and set a tricky total well in excess of 300.