The 34-year-old from Pretoria, who made his Test debut against England in December 2004, last played for his country against Australia in March this year.
Speaking in a video posted on Twitter, he said: “I have decided to retire from all international cricket with immediate effect. It’s time for others to take over, I’ve had my turn and to be honest I’m tired.
“This has been a tough decision. I thought long and hard and I’d like to retire while still playing decent cricket and after the series wins against India and Australia, now feels the right time to step aside.
“It wouldn’t be right for me to pick and choose what formats I play in, for me it’s either everything or nothing.”
De Villiers added that he would still be available to play in domestic cricket and would “still support Faf du Plessis and the squad as best I can”.
Former South Africa seamer Morne Morkel, who has recently signed a two-year Kolpak deal with Surrey, told Sky Sports News: “[De Villiers’ retirement] is a big shock with the 2019 World Cup around the corner.
“AB has played cricket for 14 years now and played every single format. After a while, I think all the pressure and all the demands get to you and at the end of the day he is human.
“He has been a great ambassador for South African cricket and he has now decided he is looking forward to a new chapter. It’s a sad day for cricket. He is loved all across the world, especially back home, and we are going to miss him dearly.”
Ex-Proteas skipper Graeme Smith told Sky Sports: “It has come out of the blue but I know AB always flirts with having had enough of the expectations, the pressures and the travel and he has played the game for long time.
“All of us want to see him be part of international cricket but there is a man with a lot of emotions and stresses and he felt it was the right time.”
De Villiers retired with a Test average of 50.66 and as the fourth-highest run-scorer for South Africa with 8,765 runs and 22 centuries.
In limited overs, he finished as the No 2 ranked batsman in the world and as the second highest run-scorer behind Jacques Kallis with 9,577 runs at an average of 53.50.
“AB is one of the all-time greats of South African cricket who has thrilled spectators around the world with his sheer brilliance, coupled to his ability to innovate and take modern day batting… to new levels,” said Cricket South Africa president Chris Nenzani.
In his last international, he made 69 and six in a South African victory over Australia at New Wanderers Stadium in March to help them to a first home win over the Australians since 1970.