Williams, who is chasing an Olympics gold medal with the New Zealand sevens team this season, made the announcement at a NZR press conference in Auckland.
All Blacks coach Steve Hansen said it was great news that Williams had committed to New Zealand through to the next Rugby World Cup.
He is an extraordinarily gifted athlete and thoroughly professional in everything he does. His recommitment will bring a stability to the midfield and will allow us to build a world-class centre combination. Sonny's professionalism, both on and off the field, will not only be an asset to his fellow midfielders, but also the rest of the team," he said.
"Sonny is part of the new leadership group in the All Blacks and it's good to know that he'll be contributing in that role over the next three years.
"He's currently one of the best players in the world. His understanding of the game is now allowing him to play instinctively and I believe he'll only get better and better. He could end up being one of the greats of our game."
Blues coach Tana Umaga said Williams' influence will be significant for his new team, his third New Zealand Super Rugby franchise, both on and off the field.
"Sonny is a marquee international player, and first and foremost he is here to play. His experience and expertise will be a major asset to a young backline," he said in a statement.
"Off the field he brings leadership and a thoroughly professional attitude and approach that will hugely benefit our club and our players."
Blues chief executive Michael Redman said the announcement is significant for the organisation.
"In our view Sonny is one of the most prized signatures in rugby right now.
"This announcement is a further reflection that we are moving in the right direction, that Sonny relishes the challenge and opportunity to help us realise our ambitions and believes we have the environment, coaching and direction to achieve them."