Apollo 13 is often called a "successful failure" because of the way NASA managed to turn the situation around and successfully bring the astronauts home. But just how did the failure happen in the first place? Through a perfect storm of incredibly unlikely, but aligned, events.
Commenter Spaceman3k set out the whole sequence — which started undramatically enough with a simple, dropped oxygen tank, and from there just kept on spiraling through a series of small coincidences that, all together, added up to a disaster.
Fortunately, a similar series of both a few lucky coincidences, and several clever moves by the astronauts and mission control, also lined up to find a way to bring them back.
The Apollo 13 story still amazes me, in that (a) there was such an unrealistic chain of events that led to the oxygen tank explosion, and (b) there was an unrealistic set of events that kept them alive. If they were to make a movie about it as if it were a fictional story, everyone would go "oh, come on, that's too coincidental!".
Consider the chain of events for the oxygen tank:
1. The tank for an earlier Apollo mission was dropped and slightly damaged, so they replaced it. Apollo 13 got the refurbished one. A drain line in the tank was slightly displaced.
2. When retesting the tank, they could fill it but not drain it properly. So they said "we'll just heat up the tank until the pressure cracks the overpress relief valve to get the oxygen out."
3. Turns out that a power connection for the tank hadn't been upgraded to a higher voltage setting, so too much power went into the tank and fused the heater thermostat closed, so that it wouldn't cut the power to the heater at the upper temperature limit.
4. When the techs powered on the heater, their gauges only went up to 80 degrees F, but the actual temperature inside the tank got up to an estimated 1000 degrees. Nobody knew it because they looked at the gauge and saw it said 80 (though it was pegged off-scale high).
5. The heat in the tank did get the oxygen out, but it also burned away the insulation on the wires to the fans which stirred the cryo in the tank. When filled up with cryogenic (liquid) oxygen, it covered the bare wires, which wouldn't spark in liquid, only in gaseous oxygen.
6. During the mission, a cryo pressure sensor failed (which was completely unrelated to anything else that was about to happen). In response, Mission Control changed their plans to have the tanks stirred every few hours instead of once per day. If the sensor hadn't failed when it did, then the next time the crew would have stirred that tank would have been in the vicinity of the moon - in which case they would have consumed too much power to have enough to make it back home; or even when the two astronauts were on the moon - in which case the LM wouldn't have been available as a lifeboat.
7. The explosion happened because there was enough gaseous oxygen near the bare wires, and a spark from the wire blew out a side panel and basically killed the electrical system, leaving them a very short time before it was completely dead. In a simulation session a couple years before, the sim team came up with the idea to force the crew into the lunar module and use it as a lifeboat. The flight controllers used their notes from this sim as the starting point for the Apollo 13 case.
If the explosion had happened earlier or later on the way to the moon than it did, they would not have had enough cryo to last as long as they did (they literally had just a few hours of margin by the time they got back to earth). If it had happened after the LM separated and went to the surface, they wouldn't have had the LM for a lifeboat; the two guys on the surface would be able to make it back to the CM - no telling if the CM would have run out of power by that point or not - but they couldn't have gotten home because the LM wouldn't have had the resources to keep the men alive (oxygen and fuel, plus the descent engine would have been on the lunar surface). If it had happened on the way home, they wouldn't have even had the LM at all because it would have been jettisoned after the moonwalkers got back in the CM.
There was an incredibly narrow window for the explosion to have happened and the astronauts still come back alive, literally just a handful of hours.
Image: Astronauts John Swigert and James Lovell wait to be picked up after splashing down in the South Pacific. / NASA