Legends mention the origin of the town in 58 BC, but the first written records of Mulhouse date from the twelfth century. It was part of the southern Alsatian county of Sundgau in the Holy Roman Empire. From 1354–1515 Mulhouse was part of the Décapole, an association of ten Free Imperial Cities in Alsace. The city joined the Swiss Confederation as an associate in 1515 and was therefore not annexed by France in the Peace of Westphalia in 1648 like the rest of the Sundgau. An enclave in Alsace, it was a free and independent republic associated with the Swiss Confederation until, after a vote by its citizens on 4 January 1798, it became a part of France in the Treaty of Mulhouse signed on 28 January 1798, during the Directory period of the French Revolution.
After the Prussian victory in the Franco-Prussian War and the Otto von Bismarck engineered unification of Germany under Prussian King William I as the new German Kaiser, Mulhouse was annexed to the German Empire as part of the territory of Alsace-Lorraine (1870–1918). The city was briefly occupied by French troops on 8 August 1914 at the start of World War I, but they were forced to withdraw two days later in the Battle of Mulhouse. Alsace-Lorraine was invaded and reacquired by France after World War I. Although never formally annexed by Germany after the Battle of France in 1940, it was occupied by German forces until returned to French control at the end of the war in 1945.
The town's development was stimulated first by the expansion of the textile industry and tanning, and subsequently by chemical and engineering industries from the mid 18th century. Mulhouse was for a long time called the French Manchester. In consequence, the town has enduring links with Louisiana, from which it imported cotton, and also with the Levant. The town's history also explains why its centre is relatively small