In the aftermath of the horrific explosion in Beirut, all the conspiracy theorists are providing "who done it" scenarios. I'd like to offer you this based on scientific and my experience working with explosives. Before working in Security, I was a Combat Engineer in the Canadian Forces and worked with all types of Explosives from commercially available Ammonium Nitrate, Forcite dynamite, Hydromex etc.. to common Military Plastic like CIL C-4 and DM-12, PETN. A US EOD Friend explained the explosion in very basic terms.
Ammonium nitrate can detonate spontaneously if it's stored in a critical mass (pile) as it was in that dock-side warehouse in Beirut. 2,750 tons of ammonium nitrate was impounded in Beirut's port after it was seized from an abandoned ship in 2014. The explosive chemical had been impounded on its way to Mozambique in 2014, the ship, the MV Rhosus, had technical difficulties while sailing in September 2013, was forced into Beirut's port, and was banned from continuing. The ship's owner abandoned it, and the cargo was kept in Beirut. Owing to the risks associated with retaining the ammonium nitrate on board the vessel, the port authorities discharged the cargo onto the port's warehouses," the summary said. The summary was published in 2015 by The Arrest News, a newsletter from a maritime-law network in Spain. Ammonium nitrate only has a shelf life of 6 months.
A particular set of circumstances is needed to turn ammonium nitrate from a stable compound into an explosive, without any fuel or external catalyst. Ammonium nitrate is classified as an "energetic material" because it produces heat as it decomposes (ages), similar to the way heat is generated by rotting material in a compost heap. If there is a sufficient quantity of ammonium nitrate, it can generate enough heat to catch fire and keep the fire going, without the need for an external catalyst or flame.
As it burns, ammonium nitrate goes through rapid chemical changes that lead to the production of oxygen. Note the O3 in its chemical formula, NH4NO3 - lots of oxygen in there. And as you know, oxygen is precisely what a fire needs to ignite, keep burning and grow bigger. As the pile spontaneously heats up the ammonium nitrate granules bond (fuse) together, creating a thick cement-like enclosure, or vessel, around the hot spot. Remember, the vessel is completely surrounded by tones of ammonium nitrate that apply pressure against its outside walls. The ammonium nitrate inside the vessel keeps on being heated and explosive gases form. The gas expands, but, inside the sealed vessel, it has nowhere to go. Eventually, at a critical pressure, the heated high-pressure gas will rupture through its containment vessel and the force of that will trigger an explosion.
Here's what happens. The gas released from the decomposing fertilizer is what drives the explosion. The energy of the initial detonation wave causes the surrounding ammonium nitrate to vaporize - instantaneously becoming a gas. The ammonium and nitrate molecules break down, and a large amount of oxygen gas is suddenly formed. The rapid release of its chemically-held oxygen, along with the energy from the detonation wave, ignites and rapidly combusts, and even more gas is released adding to the explosive yield. The result is a primary explosion and one big ass secondary explosion just like we saw in the videos of the blast that have been floating around the internet.
Hope this explains it a bit.