Ill leave the long answer for someone else, but TL;DR better morale, motivated army, crisis in Azeri politics and horrible communication leading to many desertions of military posts. Azerbaijani defence minister changed 4 times for the duration of the war.
Source: "The Black Garden" by Thomas De Waal.