Germany initially became part of the first World War due to the treaty it had with Austria-Hungary, which had declared war on Serbia due to the assassination of Archduke Franz Ferdinand. France and Russia were both also party to the war on the Allies side due to Russia's treaty with Serbia and France's treaty with Russia. The assassination basically set fire to a powder keg of mistrust that was already brewing due to the various countries interest in founding new colonies in Africa as well as Asia and the Middle East.
At the end of the war, there had been many shifts in power. The initial Central Powers were Germany, Italy and Austria-Hungary, but they were later joined by the Ottoman Empire and Bulgaria. At the same time that the Central Powers gained the two allies, it lost Italy to the Allies. Italy had a treaty with Germany to fight with them in the event of war, but Italy broke that treaty to join the Allies. Although the history of the war often focuses on Germany and the other powerful countries involved, in the end there were 32 countries total in the war with only five of them belonging to the Central Powers.