The failure of the Ludendorff offensives on the Western Front exhausted the German armies. The French army was on the verge of collapse, and by attempting to defeat the British, because they were the primary competent military opponent, instead of breaking the French forces in some other sector of the front Ludendorff defeated himself. The starvation of materiel and food caused by the British oceanic blockade was the main factor in the long strangulation of the German forces, and the increasing flow of manpower and materiel from America was beyond their power to impede or resist.
Under the stress of the German offensives in the West, which nearly broke the allied forces, General Foch was appointed Generalissimo of the Entente forces, the first unified command in the war (and one which Sir Henry Wilson, head of the Imperial General Staff, had foreseen even before the war would eventually be necessary). After the German offensives had stalled for lack of supplies and manpower the American Army began a series of offensives which pushed the German troops back to the Hindenburg Line and then broke through.
Meanwhile, the collapse of Austria-Hungary and their surrender opened the way for the British troops in Salonika to have the theoretical ability to move through Austria and invade the "soft underbelly" of Germany. After Russia's surrender German troops had continued moving into the Ukraine, and these forces would of course be cut off and useless to defend the homeland. At this point Ludendorff lost his nerve, and Hindenburg concurred that the ability of the German Army in the West to resist was compromised, and their ability to defend the anticipated thrust from Greece was nonexistent. Ludendorff insisted that the government apply to the Entente Powers for an immediate armistice, or ceasefire.
Prince Max of Baden had just been persuaded that it was his duty to take over as Chancellor. Faced on his first day in office with this demand for an immediate ceasefire, he asked the military to give him even a few days space. He felt that if the army could stabilise the front it would allow Germany to seek better peace terms. Ludendorff refused, and Max was directed by the Kaiser to proceed. In the event, the front did stabilise, still on French and Belgian territory, and the ability of the British to move north through Austria in the immediate future was nil. Still, the panic of the military leadership forced Max's government to accede to their demands. This of course led to the Armistice at 11:00 am November 11, 1918. No, there was no actual surrender. The desperation of their situation led to Germany's eventual humiliation at the Versailles peace conference, where Wilson's Fourteen Points were set aside by the French and British delegations, and a treaty which was eventually disastrous for all of Europe was forced upon Germany.
The best sources of this are found in John Toland's No Man's Land, and especially the detailed analysis of the war in B.H.L. Hart's monumental study On Strategy. For an understanding of the effect on the German soldiers and their homeland, see Erich Maria Remarque's novel The Road Back, sequal to All Quiet on the Western Front.