Aina�i existed for centuries as a Livonian fishing village. The town itself was first mentioned in 1564, and through the ages, changed hands among various barons and estates. Aina�i entered a great period of growth in the 1870s, when its history of shipbuilding and seafaring began.
In the 19th century, Vidzeme and Courland were covered with vast forests of pine trees. Aina�i's strategic position on the sea and proximity to lumber made it a perfect place for ship building. In 1864 Kri�j?nis Valdem?rs sponsored the first nautical school in Latvia, training young Estonian and Latvian farmers to become ship captains for free. The school stood for 50 years until it was destroyed in World War I. With the opening of the school and shipbuilding industry, Aina�i grew for the rest of the 19th century. From 1857 to 1913, over 50 seaworthy vessels were built in the town, and in 1902 a working port and railway station opened. By World War I, Aina�i was the fourth largest port in all of Latvia and chief in Vidzeme, overtaking neighboring Salacgr?va. The town also had its own windmills, fish-processing plant, and brick kiln.
In World War I Aina�i was heavily damaged. The port was ruined and the entire shipping fleet destroyed. In February 1919, the Estonian army drove the Germans from Aina�i and subsequently occupied it. After the war, Aina�i fell into Latvian territory, even though the majority of the population was Estonian, but Estonia's troops remained stationed there until 1920 and Estonia kept the northern section "Ikla".
In the first Republic of Latvia (1918�1940) Aina�i was revitalized. The Aina�i fleet, sunken in the war, had completely barricaded the harbor and had to be removed. The harbor was then deepened, and the port was rebuilt in 1923 with new breakers. In 1930 the Aina�i lighthouse was built.
In World War II, however, Aina�i was destroyed again. The second naval academy burned down, the port was bombed, and the warehouses were