Ayer is a town in Middlesex County, Massachusetts, United States. Originally part of Groton, it was incorporated February 14, 1871 and became a major commercial railroad junction. The town was home to Camp Stevens, a training camp for Massachusetts volunteers during the American Civil War. Later, Fort Devens was established by the federal government to train New England soldiers for World War I. Fort Devens was a major influence in the area until its closure in 1994. The town's population was 7,427 at the 2010 census.
For geographic and demographic information on specific parts of the town of Ayer, please see the articles on Ayer (CDP) and Devens, Massachusetts.
Ayer's history dates back to 1667, when the first mill in the agricultural community was built. The settlement sits on what the Nipmuc Indians called Nainacocius. A brook remains with that name. Originally part of Groton, the community was initially called Groton Junction or South Groton. The town of Ayer was incorporated in 1871, named in honor of Dr. James Cook Ayer, a prominent resident of Lowell who provided the funding for the construction of the Town Hall.