 Williams served in the Pennsylvania State Senate from 1838 to 1841, then returned to private practice.During the American Civil War, Williams returned to public office, this time becoming a United States representative, a position he held from March 4, 1863 – March 4, 1869.In his last term as representative, he was one of the managers (roughly equivalent to a prosecutor) in the impeachment of United States President Andrew Johnson.