The 32-year-old had played 77 tests for the world champion All Blacks in his 10-year international career. Ian Jones played 79 tests for the national side.
"Guys, I just want to let you know first that I'm retiring from international rugby. I'm hanging up the black jersey," the Auckland Blues captain wrote on his Twitter feed.
"It's been an amazing 10 years but it's time to call it quits. But I'm not hanging up the boots yet."
An athletic lock renowned for his intelligence and sense of humour, Williams made his All Blacks' debut in 2002 against England and was a near automatic choice for most of his career.
He suffered a serious Achilles injury in 2009 and needed three operations before returning to win the World Cup on home soil in 2011, though he was mainly used off the bench.
Williams had been named in an initial extended training squad for next month's tests against France, but chose to retire before the second camp was scheduled to be held this weekend.
The All Blacks squad for the three test series is due to be named on June 2.
"He is a player who has always worn his heart on his sleeve, he is a real character who loved being an All Black and wearing the jersey proudly and representing his country, and that's what we love about him," All Blacks coach Steve Hansen said in a statement.
"He would have played a lot more games for the team if injuries hadn't robbed him of the opportunity.
"But it took a lot of courage to come back to top-flight rugby and that is a measure of the man and shows just how much he loves the game."
- Sports & Recreation
- All Blacks