Williams was without a club after leaving championship side Bristol City at the end of the 2019/2020 season.
Williams won 86 caps for the Welsh national team and captained his country to the EURO 2016 semi-finals where they lost out to eventual winners Portugal.
He also captained Swansea City to Premier League promotion in 2011 before winning the League Cup with the Welsh club two years later. Williams also played for Everton and Stoke City.
In a statement, Williams said: "After consideration of recent offers to continue playing, I would like to announce my retirement as a professional footballer.
"It has been an honour to play 741 games across all levels of the English football league and to represent some incredible teams.
"It has been an unbelievable journey and one I will look back on with my family and be immensely proud of.
"Captaining Wales in a European Championship semi-final in 2016 was my greatest achievement and something I will never forget.
"Football has taught me so much both on and off the field and I will take this with me into the next chapter. I look forward to still being involved in the game in the future."