If a defendant utilizes an affirmative defense, then the defendant has the obligation and burden to prove the affirmative defense by a preponderance of the evidence.  If an affirmative defense is offered, the prosecution still has the burden to prove every element beyond a reasonable doubt.  In the context of a jury trial, the jury or judge (non-jury trial) must first determine if the People have proven their case beyond a reasonable doubt.  If they have not, then the case ends, and the jury or judge must issue a not guilty verdict.  If a jury believes that the prosecution proved their case beyond a reasonable doubt, then if a defendant has raised an affirmative defense, the jury must consider and determine if the defendant has proved the affirmative defense by a preponderance of the evidence.