How did the word lunatic originate?

The term "lunatic" derives from the Latin word lunaticus, which originally referred mainly to epilepsy and madness, as diseases thought to be caused by the moon.