Acidity. Most bacteria prefer neutral growing conditions. The enzymes bees use to break down the sugar in nectar make it more acidic and less appealing for bacterial growth.
Sugar content. Honey has a lot of sugar, but only 18% water, which is not sufficient for most bacteria to grow. Honey has so much sugar that it's hygroscopic - which is the ability to absorb moisture out of the air. When honey is exposed to humidity, more water is added, and when the water content rises above 25%, bacteria will eventually be able to grow. That is why the container of honey should be closed.
Antimicrobial compounds. Hydrogen peroxide is produced as a byproduct of some of the enzymes used by bees to digest more complex sugars. Some honey types also contain antimicrobial compounds such as defensin-1, an antibiotic produced by bees.
Combined, these three properties mean honey is very stable as long as it's not exposed to outside moisture or humidity.