South Africa will go back to the top of the International Cricket Council Test rankings after some stubborn batting helped them to a hard-fought draw against Sri Lanka in Colombo.
Resuming on 38 for one, chasing a nominal 369, the tourists knew they only needed to bat out the final day of the second Test to seal a 1-0 series victory, which would be enough to displace Australia in the rankings, and they just about held on.
Rangana Herath and Dilruwan Perera shared eight wickets in spin-friendly conditions, with the former claiming 5-40, but some gritty batting from the Proteas helped them close on 159 for eight after 111 overs.
Captain Hashim Amla led the way, using up 159 balls for 25, while Vernon Philander's unbeaten 27 off 98 deliveries saw South Africa home.
Perera removed Dean Elgar after a rain delay, before another shower forced an early lunch.
In the afternoon, Quinton de Kock perished for 37 off 92, which brought together Amla and AB de Villiers, South Africa's two most experienced batsmen and arguably their best players of spin.
Amla survived a drop while on 13 off Herath but the batting duo put on 25 at a fraction more than a run an over before De Villiers was bowled by Herath for 12 off 67 deliveries.
And Sri Lanka would have felt they were in with a real chance when they removed Amla and Faf du Plessis, both caught at slip by Mahela Jayawardene, in the space of five overs after tea.
In-between another delay for rain, JP Duminy hung around for 65 before he became the last recognised batsman to depart, trapped in front by Perera.
A grandstand finish was guaranteed when Herath claimed his five-for by removing Dale Steyn, but Philander repelled the slow left-armer and Perera in the closing stages to leave Sri Lanka cursing their fortunes.