Soon after his return, Anderson was approached about running for public office. In 1956, Anderson was elected State's Attorney in Winnebago County, Illinois, first winning a four-person race in the April primary by 1,330 votes and then the general election in November by 11,456 votes. After serving for one term, he was ready to leave that office when the local congressman, 28-year incumbent Leo E. Allen, announced his retirement. Anderson joined the Republican primary for Allen's 16th District seat—the real contest in this then-solidly Republican district—with four other contenders. He won first the primary (by 5,900 votes) in April and then the general election (by 45,000 votes) in November. He served in the United States House of Representatives for ten terms, from 1961 to 1981.