There is no one answer to this. It failed, but to say why it failed suggests that we might point to one thing which, if done differently, could have saved the offensive and it is very difficult to determine that with any confidence.
The Germans thought a lot about this though. The plan for the war that would eventually become WWI was drawn up in its most basic form by Count Alfred von Schlieffen and called, as I'm sure you remember, for Germany to deliver a knockout blow to France before Russia could mobilize for war, enabling the German army to wet their boots in the Channel before pivoting and making a sprint for Moscow.
When we say that they thought a lot about this it's hard for a modern reader to appreciate it. The best illustration I have found is in lanugage. In German military circles the Zero Hour of the Schlieffen Plan -- the moment the German army stepped off and began hostilities -- was simply called "Der Tag."
The Day
The simplicity of that phrase suggests the single minded focus the plan received. Of course, Schlieffen himself didn't live to see his plan in action and it fell to a General Moltke to implement it.
Moltke, however started off with the plan and then... well I don't want to say "improvised" but he certainly took the "no plan long survives contact with the enemy" approach. The plan called for german forces to swing south through Belgium and into France like a hammer to smash against the anvil of German forces is the South but when those southern forces started to deliver real victories of their own Moltke gave them more troops and and freedom to attack. Meanwhile British forces were getting involved because of the violation of Belgian neutrality and the Russians, fully aware of their own slowness to mobilize, had gotten a jump on the process well in advance of the first shots being fired and were proving a greater concern than anyone had thought in the East.
Perhaps some of these factors broke the German offensive. Perhaps all of them. Perhaps none. There is no shortage of opinion that Moltke bungled the attack by deviating from the plan and while the German military certainly thought that it could win its two front war with Schlieffen's plan we have no way to be sure. Germany certainly would not have been the only country to march into the fields of France woefully unprepared for the horror that awaited them.