Jayawardene will quit from the five-day format after the South Africa and Pakistan series next month. However, he will continue to play ODIs. In April this year, he bid adieu to T20 Internationals after winning the World T20 trophy in Bangladesh.
The 37-year-old's final Test will be against Pakistan in Colombo from August 14 to 18.
"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, but I believe this is the right time," Jayawardene, who has so far played 145 Tests, a Sri Lankan record, said on Monday.
Jayawardene made his Test debut against India in August 1997. He has so far scored 11,493 runs with 33 hundreds and 48 half centuries.
He is the joint highest Test run-getter for Sri Lanka with Kumar Sangakkara.
Jayawardene has four more Tests before he retires. He will face South Africa from July 16 in Galle in the first Test. The second and final Test of the series against the Proteas is from July 24.
The two-Test rubber against Pakistan, his farewell series, will commence in Galle on August 6.