Vehkalahti county was mentioned in the documents for the first time in 1336. At the proposal of Count Peter Brahe, the area surrounding the church of Vehkalahti was separated from rest of Vehkalahti in 1653 and it became a town called Vehkalahden Uusikaupunki (Veckelax Nystad in Swedish, "Newtown of Vehkalahti"). The town was destroyed during the Great Northern War in 1712.
As the important foreign trade town of Viipuri was surrendered to Russians in 1721, this town (newly renamed in honor of the King Frederick I of Sweden in 1723) was intended to replace it. The town, hitherto a small domestic trade port with restricted trade, was granted extensive privileges including foreign trade. Finnish people soon shortened the name to Hamina. The rebuilding of the town took place in 1722–1724. The star-shaped fortress and the circular town plan are based on an Italian renaissance fortress concept from the 16th century. Fortress towns like this are quite rare, another example is Palmanova in Italy.
In 1743 Hamina was surrendered to Russians, after the Russo–Swedish War, 1741–1743, and the town of Loviisa was the next Swedish candidate for an Eastern-Finnish trade centre. Hamina became a Russian frontier town, for which a fortress was desirable.
The Treaty of Fredrikshamn (1809), by which Sweden ceded Finland, including parts of the province of Lappland and the Åland Islands, was signed in Hamina. Thus Sweden was split and the eastern half, along with previously conquered territories including Hamina (Old Finland), was formed into the Grand Duchy of Finland, an autonomous part of the Russian Empire.
Hamina Cadet School was founded in 1819 and it was in function until 1903. In 1920 the Reserve Officer School began in the same facilities.
Because the town was once founded next to the Vehkalahti Church, the municipal center had always been inside the town borders. Vehkalahti and Hamina were consolidated in 2003, and the old coat of arms