There was a movement in the Ottoman Empire in favour of an alliance with France and Great Britain. Figures such as Talat Pasha favored an alliance with the Allied powers. It was impossible to reconcile an alliance with the French however, as France's main ally was Russia, the long-time enemy of the Ottoman Empire since the Wars of 1828.
Germany needed the Ottoman Empire on its side. The Orient Express had run directly to Istanbul since 1889, and prior to the First World War the Sultan had consented to a plan to extend it through Anatolia to Baghdad under German auspices. This would strengthen the Ottoman Empire's link with industrialised Europe while also giving Germany easier access to its African colonies and to trade markets in India. To keep the Ottoman Empire from joining the Triple Entente, Germany encouraged Romania and Bulgaria to enter the Central Powers.
The secret treaty was signed between the Ottoman Empire and Germany on August 2nd, 1914, to enter the war on the side of the Central Powers, one day after Germany declared war on Russia. The alliance was ratified by many high ranking Turkish officials, including Grand Vizer Said Halim Pasha, the Minister of War Enver Pasha, the Interior Minister Talat Pasha, and Head of Parliament Halil Bey.
However, there was no signature from the House of Osman, and the Sultan himself had not signed it. As the Sultan was the Commander-in-Chief of the Army, as written in the constitution, this made the legitimacy of the Alliance questionable, as this would mean that the army would not be able to fight a Jihad on behalf of the Sultan. As the Sultan had wanted the Empire to remain neutral, he did not wish to command a war himself, and as such, left the Cabinet to do much of his bidding.