If you are accused of a crime, it's of the utmost importance that you have a chance to defend yourself. It's not possible to be convicted of a crime unless the prosecution can show beyond a reasonable doubt that you committed it. Since the burden of proof falls to the prosecution, you may be able to win your case and defend yourself successfully simply by placing doubt in the minds of the judge or jury.
Since there is a high burden of proof in your case, you may wish to take one of several defense angles. For instance, you may say nothing and allow the prosecution to show that there is no solid evidence against you. You may decide to have an alibi testify about where you were at the time of the criminal act. You may also want to state that you didn't do it and show evidence that you did not participate in the crime through video footage or other evidence.
In the case that you did commit a crime, you can defend yourself in a few ways including arguing that you committed the crime in self-defense. For example, if you were attacked in an alley and fought off your attackers, you should not end up facing an assault charge.
Sometimes, people use an insanity defense in court, but this is rare. Judges and the jury become skeptical of those who claim they did not understand what they were doing. However, if you can show that you were not in a normal mental state at the time of the crime, you may be able to plead insanity.
These are a few options open to you. Since every case is different, your attorney may advise you to use one of these defenses or something completely different.
Source: FindLaw, "Defending Yourself Against a Criminal Charge," accessed July 21, 2017