Ayer is a town in Middlesex County, Massachusetts, United States. Originally part of Groton, it was incorporated in 1871 and became a major commercial railroad junction. The town was home to Camp STevens during the Civil War. Then Fort Devens, a federal army camp was established to train New England soldiers for World War I. Devens was a major influence in the area until its closure in 1994. The population was 7,287 at the 2000 census. For geographic and demographic information on specific parts of the town of Ayer, please see the articles on Ayer (CDP) and Devens, Massachusetts.