Swansea City
In March 2008, Williams signed for Swansea City on loan until the end of the 2007–08 season, with a view to a permanent transfer. After helping Swansea win the League One title and, with it, promotion to the second tier of English football for the first time in 24 years, the move was made permanent for a reported £400,000, a club record transfer fee at the time.
On 16 September 2008, Williams scored his first Swansea goal in a 1–1 draw against Derby County. The defender impressed during his first season at Championship level, eventually going on to be named Wales Footballer of the Year at an FAW awards dinner in November 2009. Williams also picked up the Clubman of the Year award at the same event.
After finishing in eighth position during their first Championship campaign, Swansea improved on their position by one place the following season, missing out on a play-off position by a single point. Williams was part of a defence that conceded only 37 goals during that campaign, and was selected in the 2009–10 Championship PFA Team of the Year at the end of the season.
The 2010–11 season saw Swansea and Williams gain promotion to the Premier League via a play-off final win at Wembley Stadium. Williams was named in the Championship PFA Team of the Year for the second consecutive season. The season also saw him equal and surpass a club record of 106 consecutive matches, previously jointly held by Andy Legg and Gilbert Beech.
Swansea's first Premier League season began with a 4–0 loss at eventual champions Manchester City, but the club went on to finish the season in 11th place. On 24 September 2011, Williams scored his first ever Premier League goal in a 4–1 loss at Chelsea, after heading in a Mark Gower free kick.
In October 2012, Williams signed a new three-year contract with Swansea. The club's second season in the Premier League saw a ninth-placed finish and a first major trophy win in English football for Williams and Swansea, following a 5–0 win over Bradford City in the 2013 League Cup final on 24 February 2013. After captaining the team during the final at Wembley, Williams lifted the trophy with club captain Garry Monk, who had come on as a second-half substitute.
Also in the 2012–13 season, Alex Ferguson claimed that Robin van Persie "could have been killed" after being hit in the back of his head by a football which Williams had kicked at him. Despite Ferguson calling for a player ban The Football Association took no further action. (Williams denied kicking the ball deliberately into Van Persie's head.)
In July 2013, after acting as captain for the majority of Swansea's matches during the previous two seasons, Williams was permanently handed the club captaincy after Monk stepped down from the role. On 4 July 2014, Williams signed a new four-year contract with Swansea. On 19 April 2015, he was selected in the Team of the Decade at the Football League Awards.