Scots agley, aglee "obliquely, askance, awry," from a-a- entry 1 + gley, glee "to squint, look askance," going back to Old Scots gley (in the participle gleyit "squinting") & Middle English (north, northwest Midlands) glien, gleen, gleien "to be squint-eyed, glance, glisten," of uncertain origin
Note:
Middle English gleien has been compared with Old Norse gljá "to shine, glisten," though this latter meaning is only attested once for gleien and scarcely seems to account for the "squint" sense. Initial gl- in Germanic languages in any case appears to have had phonesthemic value, perhaps suggesting both movement of the eyes and radiation of light. Gleien may hence be an entirely new formation.