Former Sri Lanka captain Mahela Jayawardene will retire from Test cricket in August.
Jayawardene, 37, who has scored 33 centuries in 145 Tests, will quit after the home series against Pakistan.
"I believe this is the right time," said the batsman, who will still be available for one-day internationals.
"It was not an easy decision to make given that it has been a great privilege and honour representing my country during the past 18 years."
Sri Lanka begin the first of two Tests against South Africa on Wednesday, before they entertain Pakistan in another two-match series.
|Mahela Jayawardene's Sri Lanka career|
Jayawardene, who made his debut for his country in 1997, has scored 11,493 Test runs, at an average of 50.18.
His highest score came in Colombo in July 2006, when he made 374 against South Africa, the fourth best innings in Test history.
He made a half-century in each of the two Test matches during Sri Lanka's recent 1-0 series victory in England.
In April, Jayawardene retired from Twenty20 cricket, after helping Sri Lanka win the World T20 title, although he will still be available for next year's 50-over World Cup in Australia and New Zealand.