NGRI (not guilty by reason of insanity):
From Black's Law Dictionary, 1087, 7th Ed. (1999)
1. A not guilty verdict, based on mental illness, that usu. does not release the defendant but instead results in commitment to a mental institution. 2. A criminal defendant's plea of not guilty that is based on the insanity defense. -- Abbr. NGRI -- Also termed not guilty on the grounds of insanity
NGRI is based upon the McNaghten ruling  wherein Tindal instructed the jury:
"If upon balancing the evidence in your minds you should think the prisoner a person capable of distinguishing right from wrong with respect to the act of which he stands charged, he is then a responsible agent."
McNaghten, acquitted on the grounds of insanity, was on trial for the attempted murder of then Prime Minister, Sir Robert Peel. He mistakenly shot and killed Drummond, Peel's secretary, instead.
From The Oxford Companion to Law, 1980, Watkins defined the McNaghten rule as follows:
(1) Persons acting under the influence of an insane delusion are punishable if they knew at the time of committing the crime that they were acting contrary to law.
(2) Every man is presumed sane and to have sufficient reason to be held responsible for his crimes.
(3) To establish a defense on the ground of insanity it must be clearly proved that, at the time of committing the act, the accused was labouring 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 he was doing what was wrong. If the accused was conscious that the act was one that he ought not to do, and if the act was at the same time contrary to the law of the land, he is punishable.
(4) A person under a partial delusion is to be considered as if the facts with respect to which the delusion exists were real.
It was further refined by Perkins & Boyce in Criminal Law 959-60 (3d ed.1982):
Four points stand out and should be understood whenever reference to M'Naghten is made other than in regard to procedure. (1) It applies only in case of 'a defect of reason, from disease of the mind' and without this the following do not apply except that 'disease' as so used will be interpreted to include congenital defect or traumatic injury. (2) If, because of this 'defect of reason,' the defendant did not know what he was doing he is guilty of crime. (3) Even if the defendant knew what he was doing he is not guilty of crime if, because of this 'defect of reason,' he did not know he was doing wrong. (4) If the defendant acted under an insane delusion, and was not otherwise insane, his accountability to the criminal law is the same as if the facts were as they seemed to him to be.
Moran, author of Knowing Right from Wrong: The Insanity Defense of Daniel McNaghten 1981 [Reprint 1986], states on p 132:
There are six factors that must be analyzed to prove insanity according to McNaghten: the nature of the offender's mental illness, the degree of the functional impairment, the offender's need for treatment and availability, the offender's prognosis for rehabilitation, the offender's current and future dangerousness, and the capacity to appreciate the wrongfulness of the illegal act
Even so, and before McNaghten, the concept of NGRI was not new. For example, consider the "Hale test"  of the 1700s:
"such a person as labouring under melancholy distempers hath yet ordinarily as great understanding, as ordinarily a child of fourteen years hath, is such a person as may be guilty of treason or felony."
The widely accepted 18th century view, as defined by Tracy , that a man cannot not be held accountable if he:
"is totally deprived of his understanding and memory, and doth not know what he is doing, no more than an infant, than a brute, or a wild beast."
The "Hale test" was successfully applied as late as 1800  where Lord Kenyon argued:
"if a man is completely deranged so that he knows not what he does, if he is lost to all sense so that he cannot distinguish good from evil, and cannot judge of the consequences of his actions then he cannot be guilty of crime because the will, which to a certain extent is the essence of every crime, is wanting."
What differentiated McNaghten from previous cases was that he did not quite meet the parameters of the "Hale test." That is, McNaghten was not viewed as "a brute, or wild beast." The question with regard to his case involved what psychologist today might classify as a delusional disorder with paranoid features, rather than earlier viewed mental incapacitance. For example Moran  notes that McNaghten claimed:
"The Tories in my home city have compelled me to do this. They harassed and persecuted me, hoping to kill me,"
1) Rex v. McNaghten, 1843 England 8 Eng. Rep. 718; 10 C. & F. 200, 210
2) 1 Hale P.C. 30
3) (1724) 16 St. Tr. 695
4) R. v. Hadfield [(1800) 27 St. Tr. 1281
5) Moran R, Knowing Right from Wrong:The Insanity Defense of Daniel McNaghten, 1981 [Reprint 2000]. p 10