The situation in Europe at the start of the 20th century was, basically, that several countries had traditional rivals/enemies and also had traditional friends/allies.
The exact chain can be difficult to trace, but here are some high points:
A group of Serbs forms The Black Hand, an organization devoted to Serbian nationalism, wanting areas with a majority ethnic Serb population to become independent and/or join with Serbia. (They're fine with Montenegro, which has an overall majority ethnic Serb population and is already independent; it's mainly Hungary they have a problem with, since it contains regions with a Serb majority but the country as a whole is not ethnically Serbian.)
Gavrilo Princip assassinates the heir apparent to the throne of Austria-Hungary. hoping this will destablize the government there and allow an ethnic Serb revolt in Hungary to be successful.
Austria-Hungary issues the July Ultimatum, with conditions deliberately made as humiliating as possible to Serbia (let us pick who to fire in your military and government) and an extremely short timeframe to reply.
Serbia dithers about this. Several other countries (most notably Russia) advise Serbia to agree in the short term and hope Austria-Hungary changes its mind afterward.
Serbia ends up agreeing to nearly all of conditions in the ultimatum, but refuses to allow Austro-Hungarian delegates to participate in the investigations into Ferdinand's assassination (seriously, Serbia? You agree to remove Austria-Hungary's laundry list of military officers and government functionaries they don't like, but you quibble at this?).
Germany really wants an excuse to go to war, so they get upset when a report comes in that Serbia has agreed to the ultimatum. When they get the corrected report that Serbia didn't agree to everything in the ultimatum, there was much rejoicing.
Austria-Hungary declares war on Serbia.
Russia (friendly to Serbia, and fearing war with Germany and/or Austria-Hungary) mobilizes its forces.
Germany (Austria-Hungary's ally) tells Russia to demobilize immediately or they'll have to mobilize their forces in response.
It gets complicated here, with a lot of telegrams going back and forth between Berlin, Moscow, London and Paris. "Willy" (Kaiser Wilhelm II) and his third cousin "Nicky" (Tsar Nicholas II) regretfully inform each other that factors beyond their control are forcing them to mobilize their armies, but that they don't really mean anything by it and everything would be just ducky if the other guy would demobilize. The end result is:
Germany declares war on Russia.
Germany and the Ottoman Empire sign a secret treaty, pulling them into the war as well.
France (Russia's ally) declines Germany's request to remain neutral, stating, essentially, that "France will act in its interests."
It's pretty clear to the Germans that France's interests do not coincide with Germany's, so: Germany declares war on France.
This war is a little problematic for Germany because France has been extensively fortifying its border with Germany for quite some time now (the Maginot Line). France's border with Belgium, on the other hand, is relatively unguarded, and Germany shares a border with Belgium as well, so...
Germany notifies Belgium that they have two choices: they can either allow German troops free passage across Belgium, or be treated as an enemy.
Britain (sorta-ally of both France and Russia, and very concerned about Belgian neutrality) seeks assurance from Germany that the Treaty of London (ensuring Belgium's neutrality) will be honored.
Germany pointedly fails to give any such assurance.
Britain declares war on Germany.
Austria-Hungary finally declares war on Russia.
Japan (Britain's ally) declares war on Germany.
At this point we've got Germany and Austria-Hungary (and nominally Italy) on one side in the Triple Alliance, with Germany additionally having a secret treaty with the Ottoman Empire, and Russia, France, and Britain on the other side in the Triple Entente, with Britain additionally having an alliance with Japan and Russia sending aid to Serbia (who by now is actually a minor player despite having set the whole thing off).
Italy wasn't entirely happy about being in the Triple Alliance and had been making overtures towards Britain and France for several years, because Austria was a traditional rival and had some territories Italy wanted, so a few months in they broke off with Germany and Austria-Hungary and joined in on the opposing side.
The US didn't get involved for several years for a couple of reasons. One, the war was a long way away and didn't greatly impact the US at first; two, while there were a lot of Americans of British descent there were also a lot who were of German descent (sometimes these were even the same people, due to intermarriage) so they didn't really have a "dog in the fight"; three, there were a lot of Americans of Irish descent who were perfectly happy to see the British getting their arses kicked no matter who was doing the kicking, and they were agitating for the US to stay out of it.
In short: it spread so quickly mainly because Germany was just itching for a war, and when the Balkan Crisis gave them justification for one they jumped at the chance. Their initial target was Russia (for a lot of reasons), but they had their eyes on some British and French overseas possessions as well, so while they would have been happy to leave France and Britain alone for a while if they'd been allowed to, fighting them was one of their long-term goals anyway.