After the Thirty Years' War broke out, a Catholic bishop was elected in 1623, and the city was occupied by troops of the Catholic League in 1628. The Gymnasium Carolinum was upgraded to a Jesuit university in 1632, but the university was closed a year later when the city was taken by Swedish troops and restored to Protestant control. Peace negotiations took place in Osnabrück and the nearby city of Münster from 1643 to 1648. The twin Treaties of Osnabrück and Münster, collectively known as the Peace of Westphalia, ended the Thirty Years' War. Osnabrück was officially recognized as bi-confessional Catholic and Lutheran. The prince-bishopric would be held alternately by a Catholic bishop and a Lutheran bishop. The Protestant bishop would be selected from the descendants of the Dukes of Brunswick-Lüneburg, with priority given to the cadets of what became the House of Hanover. From 1667, prince-bishop Ernest Augustus, Duke of Brunswick-Lüneburg, built the new baroque palace. His son, George I of Great Britain, died in the palace, at the time residence of his younger brother, prince-bishop Ernest Augustus, Duke of York and Albany, on a travel on 11 June 1727. In the early 18th century, renowned local jurist and social theorist Justus Möser wrote a highly influential constitutional history of the town, the Osnabrücker Geschichte. Following the Seven Years' War, the town's population fell below 6,000, however an economic revival linked to the linen and tobacco industries caused it to rise again from the 1780s onwards. 19th century The French Revolutionary Wars brought Prussian troops into the city in 1795, followed by the French in 1803. As a result, the town's population was kept below 10,000 for the whole first decade of the 19th century. The Napoleonic period saw possession of the city change hands several times. Control of Osnabrück passed to the Electorate of Hanover in 1803 during the German Mediatisation, and then briefly to the Kingdom of Prussia in 1806. From 1807 to 1810 the city was part of the Kingdom of Westphalia, after which it passed to the First French Empire. After 1815, it became part of the Kingdom of Hanover. The town's first railway line was built in 1855, connecting it with Löhne. Further rail connections appeared over the following decades, connecting Osnabrück with Emden from 1856, Cologne from 1871 and Hamburg from 1874. In 1866, Osnabrück was annexed by Prussia after the Austro-Prussian War