After the First Partition of Poland in 1772, Königsberg became the capital of the newly formed province of East Prussia in 1773, which replaced the Province of Prussia in 1773. By 1800 the city was approximately five miles (8.0 km) in circumference and had 60,000 inhabitants, including a military garrison of 7,000, making it one of the most populous German cities of the time.
After Prussia’s defeat at the hands of Napoleon Bonaparte in 1806 during the War of the Fourth Coalition and the subsequent occupation of Berlin, King Frederick William III of Prussia fled with his court from Berlin to Königsberg. The city was a centre for political resistance to Napoleon. In order to foster liberalism and nationalism among the Prussian middle class, the “League of Virtue” was founded in Königsberg in April 1808. The French forced its dissolution in December 1809, but its ideals were continued by the Turnbewegung of Friedrich Ludwig Jahn in Berlin. Königsberg officials, such as Johann Gottfried Frey, formulated much of Stein’s 1808 Städteordnung, or new order for urban communities, which emphasised self-administration for Prussian towns. The East Prussian Landwehr was organised from the city after the Convention of Tauroggen.
In 1819 Königsberg had a population of 63,800. It served as the capital of the united Province of Prussia from 1824 to 1878, when East Prussia was merged with West Prussia. It was also the seat of the Regierungsbezirk Königsberg, an administrative subdivision.
Led by the provincial president Theodor von Schön and the Königsberger Volkszeitung newspaper, Königsberg was a stronghold of liberalism against the conservative government of King Frederick William IV. During the revolution of 1848, there were 21 episodes of public unrest in the city; major demonstrations were suppressed. Königsberg became part of the German Empire in 1871 during the Prussian-led unification of Germany. A sophisticated-for-its-time series of fortifications around the city that included fifteen forts was completed in 1888.