Doctors revealed he had damaged the tendons and ligaments in his shoulder joint and would require surgery to fix the problem unless he rested.
Williams has decided not to play through the pain barrier this summer and risk not being fit in time for next year's World Cup in New Zealand.
The Wales wing hopes his summer off will allow him to skip the surgery with an international swansong at the World Cup in mind but insists it was one of the hardest decisions of his career to date.
"I had to let my head rule my heart - I have been struggling with this problem for a while and I've decided a rest will be better for me in the long run," said Williams.
"Next year is such a big one for me, for all of the Wales team, and I want to be right for it. I'm heading into my last international season which is very important.
"I have to work incredibly hard to stay involved and the key consideration in all this is me getting the chance to have a good pre-season for the first time in about six or seven years.
"I am absolutely gutted to missing these matches and I found telling Warren Gatland and Rob Howley extremely hard because I've never had to do it before."