Sri Lanka 421 (Jayawardene 165, Dickwella 72, Mathews 63) and 229 for 8 dec (Sangakkara 72, Mathews 63*, Morkel 4-45) drew with South Africa 282 (Amla 139, Perera 5-69, Herath 4-71) and 159 for 8 (Herath 5-40, Perera 3-60)

Scorecard and ball-by-ball details

After a riveting, un-Youtubeable day of cricket, South Africa are back at the top of the Test rankings. The settings were dramatic - leaden skies for most of the day, four or more men poised round the bat, the indefatigable spinners rifling through their overs and some of the world's most flamboyant batsmen in the middle.

And the batsmen deadbatted virtually everything to hang on for the draw that they were seemingly aiming for since midway through the second day. A few-minutes-long clip can't capture the technique, temperament and concentration needed to survive against a misbehaving ball on a raging turner or the feeling that every delivery could transform the game. Edges, noisy appeals and getting beaten are unavoidable even for the very best batsmen, but those can't be allowed to shake your focus.

On a day when South African fans prayed more for rain than for runs, the rain intermittently interrupted play but Sri Lanka still wheeled in 94 overs. South Africa ended on 159 for 8 in 111 overs - their slowest effort this century, slower even than the great escapes in Johannesburg and Adelaide. It was also their first Test series win in Sri Lanka since 1993, extended their incredible eight-year unbeaten run on the road, and made light of the recent loss of two giants in Jacques Kallis and Graeme Smith.

At tea, Sri Lanka had taken only four wickets and those consummate match-savers, Hashim Amla and Faf du Plessis, were in the middle. In the space of five overs, though, both were dismissed to slip catches by Mahela Jayawardene - who became the third to 200 Test catches - and Sri Lanka's spirits were further lifted as the grey skies changed to mostly blue. Umbrellas that young fans had been using to keep out the rain, were now being used to keep out the sunshine.

That left JP Duminy and the tail more than two hours to survive. Two hours for the Sri Lanka spinners to mop up the innings. In the first innings, Duminy had blotted out 58 deliveries to score 3; this time he took 65 deliveries to score 3. Vernon Philander showed the ability that has helped him bat 337 deliveries in his previous four innings, and with short bursts of rain eating up another 25 minutes, South Africa were breathing easier.

About 75 minutes remained when the players returned, and Duminy fell just as the final hour began - late in bringing down the bat against Dilruwan Perera. The anxiety levels shot up further for South Africa when Dale Steyn attempted an extravagant against-the-turn cover drive on his first ball.

With Ajantha Mendis showing no rhythm, Angelo Mathews not bowling, and the only specialist quick, Suranga Lakmal, hardly used, Sri Lanka were essentially down to a two-man attack of Rangana Herath and Perera. Mendis sent down only 13 overs in the final innings, more than 30 less than Herath and Perera each did. Herath has bowled 172 overs in the series, Perera 158.3, and they wheeled away tirelessly on the final day as well.

In the final hour, Sri Lanka frequently had all their fielders round the bat - a six-man catching crowd on the off side, and three lurking on the leg side. The appeals were becoming desperate, wicketkeeper Niroshan Dickwella getting on bended knee as he pleaded with the umpires, when Herath produced the breakthrough, getting Steyn to nick to the keeper.

Imran Tahir had whacked his helmet with his bat in frustration after being dismissed in the first innings. He had drawn a somewhat similar reaction from South Africa fans with his wayward bowling this series, but called on to block out the final half hour, he delivered.

With Philander calmly tapping everything away, and Tahir defending with exaggerated caution - the ball barely rolled a foot away after one of his crouching forward defensives - time began to run out for Sri Lanka. Suddenly South Africa's batsmen were calling for a change of gloves, a drink or anything the 12th man could run out to deliver and eat up precious minutes.

It came down to the final over, and the tension was so unbearable that Quinton de Kock pulled the top of his shirt over his head in the dressing room to avoid having to watch. Tahir, who was cramping badly, was lying prone on the ground - prompting remarks about footballers faking injury - but once he was back on his feet, an unflustered Philander kept out the six balls from Herath, tucked his bat under his arm and walked off. This is the third time in four Tests that it was a final-over finish for Sri Lanka - they came out on top in both games in England, but there was no joy this time.

They were undone by a team effort from South Africa, with not a single wicket going down to a rash stroke or a rush of blood. Amla was the stand-out batsman, but almost all the others also stuck around for at least an hour as their technique was rigorously examined by Herath and Perera. Herath was so precise that in his 27 overs before tea, the batsmen could leave alone only 10 deliveries while Perera kept tossing the ball up, and was unerringly accurate.

South Africa got an early indication of what to expect when Dean Elgar lost his offstump to a delivery that spun sharply across the stumps. Quinton de Kock was the most positive of the batsmen, but he had several leading edges as he looked to work plenty of deliveries to leg. He finally perished, caught at backward short leg for a relatively brisk 37.

That brought together South Africa's two best batsmen, Amla and AB de Villiers. Sri Lanka used up both their DRS appeals on de Villiers, once when he was yards out of the crease and the ball nowhere near the bat, and another in the 58th over when he survived a close lbw call. Amla hit two early boundaries, and then played out 57 successive dot balls. He was dropped by Angelo Mathews at gully in the 49th over, and was troubled by his hamstring, but nothing shook him out of his thou-shalt-not-pass approach.

Sri Lanka's fielders were quietened as the partnership stretched towards 25 overs, before Herath produced a ripper that drifted in and spun away to take de Villiers' off stump. Du Plessis survived a first-ball lbw through the DRS, and Amla was reprieved soon after tea when a certain lbw was turned down. Fortune seemed on South Africa's side, but there was to be no cruise to the finish line, as Herath removed both batsmen to set up a nerve-shredding finale.

A Test which began with a manic first session where runs were scored at 4.42 runs an over, ended with a session in which runs were scored at 1.38 an over.