The defeat was due to a failure to account for distance, logistics, and the nature of the German Army.
The fundamental thing to remember about the German Army of 1941 is that it was in fact a fairly advanced industrial-era army. People keep making fun of the German Army's reliance on horses, or take it to the other extreme and pretend it's an ultra-modern army with super tanks and aircraft. The truth is somewhere in the middle slanting towards the latter.
There was a small core of highly trained mechanized forces - the Panzer Armees - which were indeed highly mobile and powerful. However, the bulk of the army was in fact a relatively advanced infantry army - reliant on the power of heavy automatic weapons and artillery - which was very devastating against an enemy that was still reliant primarily on masses of riflemen.
These two worked in concert against the Red Army - which at the time was in the midst of reorganization and hence their unit quality varied widely and the coordination between them was nearly non-existent. On one hand you had some very good Soviet Mechanized Corps with monstrous tanks and professional infantry, but you also had masses of infantrymen who were fighting with shortages in automatic weapons and artillery (though, to be fair, there were very few instances of the "one man carries a rifle, the other picks up the rifle when the first man is killed" myth peddled by Enemy at the Gates). By contrast, the German army was a fairly well-oiled machine at this point and both portions knew exactly what they were supposed to do - the Panzers ranged far ahead, shot up the Soviet rear areas, and created pockets; while the infantry followed as best they could on foot and mopped up the pockets of resistance.
The problem, and this was known to pretty much all of the German generals even before Barbarossa, was that the distances they needed to cover were simply too great for their logistics network to support. And the German Army simply needed huge amounts of supplies - fuel for their tanks and ammunition for the artillery and machine guns being the most important - something to the tune of 1,000 tons of supplies per Division per day of combat. If the Panzer Divisions didn't get their allotments, they went nowhere because they had no fuel. If the Infantry Divisions didn't get their allotments, then they lose much of their machinegun and artillery firepower that makes them so effective. By the time they got to Moscow, the Divisions were simply no longer getting their allocations because the distance was too great.
The firepower structure of the German infantry also made them much less able to take cities - which required riflemen to be expended in great numbers and where the firepower advantage was nullified. Only around a quarter of the Division's manpower was frontline riflemen; the remainder being heavy weapons crews, artillerymen, and logistics personnel. And by the time they got to Moscow, 1/10 of their manpower was gone and the casualties had been disproportionately incurred by the riflemen - leading to some Divisions having less than half of their riflemen allotment and were left with companies consisting of only 20 (!) men apiece. "Company"-sized assaults of 20 men against fortified positions in an urban location like Moscow would have been farcical.