Duminy was dropped from the Proteas squad after the first Test at Lord's in a four-match series against England in July and has since not featured in the longest format.
In 46 Tests, Duminy scored 2,103 runs at an average of 32.85. He also picked up 42 wickets with his off-spin.
"After long and careful deliberation, I have decided to retire from first-class and Test match cricket with immediate effect," Duminy, who opted out of the opening round of domestic first-class fixtures in South Africa, said in a statement.
"It is an experience that cannot be replaced and one I will always cherish. Test cricket has always been the pinnacle and I've been fortunate enough to experience some memorable highlights with the Proteas and also in first-class matches with the WSB Cape Cobras."
Duminy made his Test debut with an unbeaten half-century at Perth against Australia in 2008 to help South Africa hunt down a target of 414, the second-highest successful run-chase in Test cricket.
"In the years ahead, my focus will be placed on attaining limited-overs cricket success for South Africa and the WSB Cape Cobras..." he added.
South Africa's next Test assignment is a two-match home series against Bangladesh from September 28.
Image: JP Duminy
Photograph: Nathan Stirk/Getty Images
Desis vs Aussies: The Numbers Game
Get set for the mother of all cricketing battles!
Why Kohli gave a thumbs down to Pepsi
India vs Australia: How the numbers stack up
REVEALED! Sehwag on why he missed out on India coach job