Bremen's first bishop, Willehad, arrived in 787, after Charlemagne's Franks had beaten the Saxons and ordered them to convert. A century later, in 888, the emperor gave the town the right to hold markets, mint coins and set its own customs rules. By 1042 North Sea trade had paid for city walls and a stone St Peter's. In 1186 Frederick Barbarossa's privilege freed property in the city from feudal taxes, and a serf who lived there a year and a day became free. That grant was the root of its later claim to be a Free Imperial City. The cathedral still dominates the market square.
Bremen joined the Hanseatic League in 1260, an alliance of northern trading towns led from Lübeck. Its merchant guilds valued the League for its hold on the North Sea salt-fish trade. By 1350 the city had 20,000 people and a name for building cog ships. The old rival was the Prince-Archbishop. The Bishop's Needle, a gate first mentioned in 1274, was cut so narrow that he could not ride in with his knights. He still took the town overnight on 29 May 1366, and exiles won it back within a month. In 1404 the city raised a new stone Roland, still facing the cathedral.
Bremen took to the Reformation early. In 1532 townspeople broke into a Catholic Mass in the cathedral and had a Lutheran pastor preach there instead. By the 1590s most citizens and the council were Calvinist, while the cathedral chapter stayed Lutheran. The Thirty Years' War then tested the city's independence. It paid Wallenstein a ransom in 1628 to avoid a siege, and in 1646 the emperor confirmed it as a Free Imperial City. Sweden besieged it in 1664, and a coalition of rival powers made it stop in 1666. In 1720 King George I of Britain, whose Hanover surrounded the city, recognised it as free.
Napoleon annexed Bremen in 1811, and the French were gone by 1813. At the Congress of Vienna, Johann Smidt won Bremen, Hamburg and Lübeck their old status as republics. The Weser kept silting up, so in 1827 Smidt bought land from Hanover at the river mouth and founded Bremerhaven. With the railways, the new harbour made Bremen the main German port for emigrants heading to the Americas, and Norddeutscher Lloyd, founded in 1857, grew into one of the world's leading shipping lines. The same trade brought in coffee and cotton, and the merchants pushed for colonies. The ten-metre brick elephant finished in 1931 is a remnant of that, now reworked as an anti-colonial memorial.
Bremen was a left-leaning port city: in 1912 the Social Democrats took 53.4% of the vote. In January 1919 a workers' council declared a Bremen Soviet Republic, and troops sent from Berlin crushed it on 4 February with about 80 deaths. In March 1933 the Nazis won 32.7% in Bremen against 44% nationally, yet the city still lost its self-rule, and the Bürgerschaft that had met since 1849 was abolished. Prisoners from the Farge camp were forced to build the Valentin submarine bunker. Allied bombing then destroyed most of the historic city and 60% of its housing. The town hall, the Roland and the cathedral survived, and citizens themselves restored the market square's façades first.
In August 1945 the Americans appointed the Social Democrat Wilhelm Kaisen mayor, and he held the post until 1965. To stop Bremen being folded into Lower Saxony, he took the case for its independence to the United States in 1946. It worked, and Bremen became one of the founding states of West Germany. The boom of the 1950s and 60s drew workers from Turkey and southern Europe, many of whom stayed. Then the shipyards went: AG Weser, which once employed 16,000, closed in 1983 and Bremer Vulcan in 1997, and unemployment reached 14% around 2000. The city has since leaned on aerospace, logistics and a university founded in 1971.