The 33-year-old lasted just 17 minutes of his side's friendly with Mexico before being forced off after a collision with Javier Hernandez.
Williams broke two ribs in the clash, which punctured his lung and then led to it collapsing.
As a result, he needed to have surgery to repair the damage, and was taken to Ronald Reagan UCLA hospital in Beverly Hills, from where he posted a message to his Facebook followers detailing his condition.
"Crazy couple weeks.. great to be back in a FA Wales shirt & with the lads, however after coming off after 20 mins with multiple breaks on two ribs, I went hospital & found out I had punctured my left lung which led to it collapsing," Williams wrote.
"I would like to say a huge thank you to all the staff at Ronald Reagan UCLA hospital in Beverley Hills for looking after me and making sure surgery went as comfortable as possible.
"Look forward to flying home & resting up now before the new season!"
The 33-year-old captained the Dragons at Euro 2016, where they surprised many pundits to reach the semi-final before losing to eventual winners Portugal.