The story
Probably from the observation that one's shadow falling upon a door whilst standing at it causes it to appear darkened. Alternatively, possibly derived from an old sense of darken meaning "to lie in wait, loiter, lurk".
Etymology from Wiktionary, CC BY-SA 4.0.