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 growth was influenced by a period of rapid development of railroad transportation. Though only 9.5 square miles (25 Square Kilometer) in area, the town became a major junction for both east-west and north-south rail lines, and developed into an important commercial center oriented towards the rail industry. Known as Groton Junction and later Ayer Junction, the intersecting railroads included.