Aloja as a settlement was first mentioned in written sources in 1449. Aloja saw rapid development after Latvian agrarian reforms in 1920. In 1925, Aloja was granted a status of a village, and it also became a centre of the parish. In 1936, the new Rīga- Rūjiena railway line was constructed through Aloja.
In 1992, Aloja was granted town rights. From 2009 until 2021, Aloja was the administrative center of the former Aloja Municipality.