The Second French Empire was the Imperial Bonapartist regime of Napoleon III and Napoleon IV from 1852 to 1890. In 1852, Napoleon III took power through a coup d'etat and declared himself Emperor. Despite ruling what became known as the "Liberal Empire" opposition to the emperor's rule grew over the years, especially as socialist, communist, and radical groups formed across the country. Napoleon IV did his best to keep the groups under control by issuing reforms, but the country was on the verge of revolution when socialists revolted in Prussia and formed the Republic of Germany. Napoleon IV declared war on the new socialist state, but to his suprise, his armies were quickly defeated by Germany. The Emperor fled to Algeria, and a new socialist French republic supported by German was created.