The consonant /h/ (the velar nasal) was not phonemic in Old English or in Middle English. Instead, the velar nasal was an allophone of the alveolar nasal /n/. This allophone appeared in OE and ME before /k/ or /g/. During EME, /g/ was lost in final position. Thus, EME /h/ became phonemic, because it contrasted with EME /n/ in final position.
For example, when /g/ was lost, EME wing /wIng/ became /wIh/ instead of just /wIn/, preserving the distinction between wing and win.