WW1 was longer than expected and Germany suffered heavy losses. It became clear that the Kaiser could no longer rule. By the end of 1918, democracy had emerged in the form of the Weimar Republic.
By the autumn of 1918, it was becoming obvious that Germany could not win the war. A series of events led to Kaiser Wilhelm abdicating (giving up leadership).
Ebert created the Council of People's Representatives as a temporary government. This Council ran Germany until new elections were held in January 1919.