In the United States, the Criminal Justice system operates under the actus resus non facit reum nisi mens sit rea mentality in many instances. This means that an act does not make a person guilty unless their mind is also guilty.
In some instances, acts or actions are a crime regardless of whether you intended to break the law or not. For instance, if you're speeding, it doesn't matter if you meant to do so or not. The fact that you were speeding is enough to constitute a violation. This is what is known as "actus reus". In most instances, ignorance of the law isn't a justifiable defense. So if you didn't see the speed limit sign, you're still going to be paying that speeding ticket.
However, in many other instances, in order to constitute a crime, there has to be intent or a "guilty mind". You have to have intended to commit the crime in order to be charged and convicted. This is known as "mens rea". For instance, if you discharge a firearm into the air and it kills someone, you probably won't be charged with homicide because you didn't intend to kill anyone. You were just an idiot. But you can be charged with reckless discharge of a firearm because you committed that act by shooting into the air. You might also be charged with some form of manslaughter because your reckless action caused a death regardless of your intent. But because homicide requires malice aforethought (or intent), which you lacked, you can't be charged with homicide.
One glaring exception to this rule is the Felony Murder Rule. In most states and common law jurisdictions, if you commit a felony and someone dies, you can be charged with that death regardless of whether or not you intended for it to happen. If you're involved in a felony (bank robbery) and your fellow bank robber kills someone, you can be charged with homicide too. Even if you didn't pull the trigger, you're complicit because you were involved in the bank robbery.
So if your character Bob is in prison for murder in the 1st because he shot into the air and accidentally killed someone...you might want to rethink that! But if Bob is in prison for murder because he was robbing a bank and John shot a guard, you're on the right track.
Need more in-depth help? Check out JRank's article on the difference between the two. You can also use the JRank Law Library to research other CJ topics of interest!