Cricket South Africa reported the news.
The opener added just five runs to a disappointing overall South African total of 287 all out. It will take an an unlikely Australian collapse for Smith's men to emerge victorious in this one, and it appears that his own recent failure with the bat has prompted his decision.
Smith relayed the news to his team-mates shortly after play had ended at Sahara Park Newlands, per Cricket South Africa:
This has been the most difficult decision I have ever had to make in my life. It's a decision that I have been considering since my ankle surgery in April last year.
I have a young family to consider, and I felt that retiring at Newlands would be the best way to end it because I have called this place home since I was 18 years-old.
Thank you from the bottom of my heart. I bid my career a fond yet sad farewell.
Smith has enjoyed a hugely successful international career, scoring over 9,000 runs in 116 Test matches, at an average of 48.72.
However, the recurrence of the ankle injury that has plagued him throughout his career has curtailed his excellence and saw him out of the game for five months last year.
Since his return, Smith has found it difficult to recapture his best form, and the timing of the announcement—in the middle of a Test match—was perhaps a surprise.
However, Smith would the first to acknowledge that his contribution hasn't been of the standard required to top the batting order.
His innings in this series read 10, 4, 9, 14 and 5, and as Peter Lalor of The Australian notes, Smith has "looked slow and muddled when facing the new ball."
Sometimes the hardest thing for a sportsman is to know when his time is up, when it's time to hand the baton over.
In making a decision now, Smith has shown the leadership and class which has carried him throughout his remarkable career.