The opening batter has played 84 tests and eight one-day internationals, scoring 5,146 runs at an average of 37.28 in the longest format, including 13 centuries and a career-best 199 against Bangladesh in 2017.
"Playing the game of cricket has always been a dream of mine but having the opportunity to represent your country is the ultimate," the 36-year-old said in a statement.
"Having had the privilege to do it for 12 years internationally is simply beyond my wildest dreams. It has been an incredible journey that I have been fortunate enough to have."
Elgar captained South Africa in 17 tests before losing the armband to Temba Bavuma in January this year. He won nine and lost six of his matches in charge, most notably beating India 2-1 in a home series in 2022.
South Africa meet India in Centurion in the opening test starting on Dec. 26 before moving to Cape Town for the second match from Jan. 3.
(Reporting by Nick Said; Editing by Peter Rutherford; Editing by Peter Rutherford)
South African captain Dean Elgar departs after he was caught lbw for two runs by Australian bowler Pat Cummins on day two of the first Test at the Gabba in Brisbane on 18 December 2022. (Photo: EPA-EFE / Dave Hunt)