The two largest contributing factors were Cortes' ability to make alliances with the outlying tribes that were enemies of the aztecs and disease.
The Aztecs' practice of ritual sacrifices had not exactly endeared them to their neighbors, since many times the Aztecs would raid their neighbors for sacrifice victims or demand them as tribute. When Cortez opposed the Aztecs, he found many tribes, like the city state Tlaxcala, willing to contribute both supplies and warriors due to their hatred of the Aztecs.
Disease is probably the largest contributing factor in the Spaniard's success in defeating the Aztecs. One of Cortes' men was infected with small pox, and the native Aztec population had absolutely no resistance or any sort of immunity built up to the deadly virus. The virus decimated the population, wiping out at least a quarter of all the inhabitants of Tenochtitlan, including the emperor, which of course disrupted the chain of command.
Another factor to consider is the stalwart Aztec belief in ceremony which required them to take prisoners alive in the heat of battle rather than killing them on the spot. They needed to take prisoners alive in order to sacrifice to their gods. This proved rather a disadvantage, overall, when it came to combat with the Spaniards. It was only through continual sacrifice that they hoped to maintain the natural order of things, to ensure the success of crops, and so on, but it meant that they could kill far fewer of their enemy outright.
It has often been observed that there was a certain fatalistic streak in the Aztecs and that they were quickly demoralized. Their faith in existence, in the survival of their civilization seemed rather precarious. For them, much depended on the favour of the gods, which could not be assured. Apparently, too, the appearance of the Spaniards seemed to them the fulfillment of an old prophecy which would result in the collapse of their world - a world they knew as the 'Fifth Sun'. Having said that, such legends as these might also have grown after the Spanish Conquest, when the demise of the Aztecs was already an accomplished fact.
While I agree to a great extent with the previous answer, I would also add that the Spaniards’ superior technologies helped them defeat the Aztecs as well.
It is absolutely important to recognize the importance of diseases and of native allies in the Spanish conquest. If diseases had not decimated the Aztecs, it would have been harder for the Spanish to win. If Aztec brutality had not angered their subject peoples, the Spanish would have had to fight alone and probably would not have been numerous enough to win.
However, we still have to account for the Spanish superiority in technology. The guns and the steel weapons and armor that the Spanish had allowed them a tremendous advantage in fighting against the Aztecs. Their steel weapons could cut through any armor the Aztecs had while the Aztecs’ weapons could not penetrate Spanish armor.
In looking at the Spaniards’ ability to defeat the Aztecs, we have to acknowledge the role of technology.