Hakodate was founded in 1454. The port of Hakodate was surveyed by a fleet of five U.S. ships in 1854 under the conditions of the Treaty of Kanagawa, as negotiated by Commodore Matthew Perry.
Hakodate port partially opened to foreign ships for provisioning in the following year and then completely to foreign trade on 2 June 1859 as one of three Japanese open ports designated in the 1858 Treaty of Amity and Commerce signed with the U.S. A mariner in Perry's fleet died during a visit to the area and became the first U.S. citizen to be buried in Japan when he was interred in Hakodate's cemetery for foreigners.
As one of few points of Japanese contact with the outside world, Hakodate was soon host to several overseas consulates. The Russian consulate included a chapel from where Nicholas of Japan is credited with introducing Eastern Orthodox Christianity to Japan in 1861 (now the Japanese Orthodox Church). The Orthodox church is neighbored by several other historical missionary churches, including Anglican and Catholic.
Hakodate also played a central role in the Boshin War between the Tokugawa shogunate and the Meiji Emperor which followed Perry's opening of Japan. Shogunate rebel Enomoto Takeaki fled to Hakodate with the remnants of his navy and his handful of French advisers in winter 1866, including Jules Brunet. They formally established the Republic of Ezo on December 25. The republic tried unsuccessfully to gather international recognition to foreign legations in Hakodate, including the Americans, French, and Russians.
The rebels occupied Hakodate's famous European-style Goryokaku fort and used it as the centre of their defences in southern Hokkaidō. Government forces defeated the secessionists in the Battle of Hakodate in 1869 and the city and fort were surrendered to emperor. Military leader, Hijikata Toshizo, was one of those slain in the fighting.