Williams was elected as a Democrat to the Twenty-sixth Congress (March 4, 1839 – March 3, 1841). He was an unsuccessful candidate for reelection in 1840 to the Twenty-seventh Congress. He was elected to the Twenty-eighth Congress (March 4, 1843 – March 3, 1845). After retiring from elected office, he resumed the practice of law and died in Taunton on May 8, 1887. He was interred in Mount Pleasant Cemetery.