Kusal Perera remarkably dominated a record-breaking 10th-wicket partnership with Vishwa Fernando to carry Sri Lanka to a sensational one-wicket win over South Africa in a dramatic first Test.

Having been set 304 to win in Durban, Sri Lanka's hopes looked to be over when they slipped from an overnight score of 83-3 to 226-9 on day four.

Perera was unbeaten on 86 when the ninth wicket fell but almost single-handedly guided Sri Lanka to one of the great Test victories thereafter, hogging the strike and reaching 153 not out in an unbroken stand of 78 with Vishwa, who faced 27 balls to make six.

Sri Lanka were therefore able to claim a 1-0 series lead, with the masterclass from Perera - whose previous Test best was 110 - leaving the hosts stunned.

Inzamam-ul-Haq and Mushtaq Ahmed had shared the previous highest 10th-wicket partnership to win a Test in the fourth innings, putting on 57 against Australia in Karachi in 1994.

South Africa were firmly on top in the morning session when Dale Steyn struck twice in an over, first ending an alliance of 58 between Perera and Oshada Fernando.

Steyn (2-71) tempted an edge from Oshada - consolidating his place in seventh on the all-time Test wickets list - and then took a superb catch two deliveries later to dismiss Niroshan Dickwella off his own bowling.

Sri Lanka and Perera dug in to reach lunch and then 200 without further loss, before another flurry of breakthroughs looked to have put the Proteas in complete control.

Dhananjaya de Silva made an impressive 48, but was lbw to Keshav Maharaj after putting on 96 with Perera.

Suranga Lakmal then fell first ball as Maharaj (3-71) contributed the second two-wicket over of the day and, with Perera battling on after taking a stinging blow to his right hand, Lasith Embuldeniya (4) and Kasun Rajitha (1) also departed.

It was all uphill from there for Sri Lanka, but Vishwa - whose first-class batting average is a measly seven - worked hard to support the rampant Perera, with South Africa unable to take the occasional opportunity to remove a clearly uncomfortable tailender.

Perera faced 200 balls in all but showed no signs of tiring, smashing a succession of brilliant maximums - five in total - as the hosts stationed several fielders on the boundary to no avail.

Amid increasing tension, a four through the vacant slip region completed one of the all-time great chases, the imperious Perera passing 150 in the process.