The first famous legal test for insanity came in 1843, in the McNaughton case.
Englishman Daniel McNaughton shot and killed the secretary of the British Prime Minister, believing that the Prime Minister was conspiring against him. The court acquitted McNaughton "by reason of insanity," and he was placed in a mental institution for the rest of his life.
However, the case caused a public uproar, and Queen Victoria ordered the court to develop a stricter test for insanity.
The "McNaughton rule" was a standard to be applied by the jury, after hearing medical testimony from prosecution and defense experts.
The rule created a presumption of sanity, unless the defense proved "at the time of committing the act, the accused was laboring under such a defect of reason, from disease of the mind, as not to know the nature and quality of the act he was doing or, if he did know it, that he did not know what he was doing was wrong."
The McNaughton rule became the standard for insanity in the United States and the United Kingdom, and is still the standard for insanity in almost half of the states.