Mens Rea - A Defendant's Mental State
Most crimes require what attorneys refer to as "mens rea", which is simply Latin for a "guilty mind". In other words, what a defendant was thinking and what the defendant intended when the crime was committed matters. Mens rea allows the criminal justice system to differentiate between someone who did not mean to commit a crime and someone who intentionally set out to commit a crime.
To give an example, imagine two drivers who end up hitting and killing a pedestrian. Driver 1 never saw the person until it was too late, tried his or her best to brake, but could do nothing to stop the accident and in fact ended up killing the pedestrian. Driver 1 is still liable, but likely only in civil court for monetary damages.
Driver 2, on the other hand, had been out looking for the pedestrian and upon seeing him, steered towards him, hit the gas pedal and slammed into him, killing him instantly. Driver 2 is probably criminally liable because he intended to kill the pedestrian, or at least he intended to cause serious bodily harm. Even though the pedestrian is killed in both scenarios (the outcome is the same), the intent of both drivers was very different and their punishments will be substantially different as a result.
Careless versus Criminal
Carelessness is generally referred to as "negligence" in legal terminology, and generally results in only civil, not criminal, liability. However, at some point general carelessness turns into something more culpable, and some criminal statutes have heightened negligence standards such as criminal or reckless negligence. For example, it may be simple negligence to leave items out on your sidewalk that cause a neighbor to fall and hurt themselves. It may be more than simple negligence, however, if you left out a chainsaw, some knives and flammable material on your sidewalk, resulting in your neighbor's serious injury.
Intentional versus Unintentional
Intentional harmful behavior is often criminal, but unintentional harmful behavior comes in two basic forms. The first is "mistake in fact" and the second is "mistake of law".
Mistake in fact means that, although your behavior fit the definition of a crime in an objective sense - you sold illegal drugs for instance - you were unaware that what you were selling was in fact an illegal drug. For example, if you gave someone a bag full of white powder in return for some money and honestly thought it was baking soda, then you are mistaken as to a fact that is critical to the crime. As a result, you likely lack the necessary mens rea or mental intent necessary under a drug law, because you never intended to sell an illegal drug, you intended to sell baking soda (note that almost no one will believe you honestly thought baking soda could be sold for that much money).
Mistake of law however, will almost never save you from criminal liability. Almost everyone is familiar with the phrase that "ignorance of the law is no excuse", and that's exactly how the law sees it. Perhaps in the above example, you did know that what you were selling was cocaine, but you honestly thought that it was legal to do so. It doesn't matter. It may seem slightly unfair that the person who was essentially dumb enough to believe that the white powder was baking soda gets off, but the well intentioned person who honestly thought it was legal to sell cocaine doesn't get off. The justification for having no tolerance for ignorance of the law is that allowing ignorance of the law as a defense would discourage people from learning the law and seriously undermine the effectiveness of the legal system.
Strict Liability No Mens Rea Required
Finally, there are some criminal laws, called strict liability laws, that don't require any mens rea at all. These laws are justified by claiming that no matter what you intended, the act itself deserves criminal punishment. Many strict liability laws involve minors, such as laws prohibiting "statutory rape" and the sale of alcohol to minors. It doesn't matter that you may have honestly thought that the minor was over 18 in the case of statutory rape, or over 21 in the case of selling alcohol. These laws often seem harsh, but the underlying theory behind it is the protection of the minor over the possible innocence of the defendant.
Committing a Crime "Knowingly"
Many criminal laws require a person to "knowingly" engage in illegal activity. Which part of the offense needs to be done knowingly depends on the crime. For example, a drug trafficking law might require that the person "knowingly" import an illegal drug into the United States. If the defendant had been given a gift to deliver to someone in the U.S., and the defendant honestly did not know that the gift contained an illegal drug, then the necessary mens rea has not been established and no crime was committed.
Committing a Crime "Maliciously" or "Willfully"
Some criminal laws use the term malicious and willful to describe the necessary conduct. Generally, this adds nothing that isn't already covered by intentionally and knowingly. However, in some murder statutes it is a "heightened" form of intentionally/knowingly, and will result in a higher degree murder charge. The difference being that it is one thing to get mad at someone and kill them in passion, but it's quite another thing to devise an elaborate plan to stalk and kill a victim.
Despite the nearly iron-clad rule that ignorance of the law is no excuse, sometimes "willfully" has been interpreted as knowing that it is illegal and doing it anyways (which requires knowledge of the law that it was illegal in the first place).
Committing a Crime with the "Specific Intent"
Specific intent crimes are crimes where an act has to be accompanied by a particular intent to do something and are often written as "[performed some physical act] with the intent to". An easy to understand example of this is theft.
Most theft statutes require that you not only take some object (the physical act), but that you take it with the intent to "permanently deprive" the rightful owner of that object. For example, imagine that you took your friends pair of sunglasses for the day, but you did so with the intent to give them back later that afternoon. You had no right to take those glasses, they belong to your friend, but what you did wasn't theft because you never had the intention of permanently keeping the sunglasses.
Why Motive Matters
Motive is an indirect way to prove that something was done intentionally or knowingly. For example, a defendant in an assault case may claim that he punched the victim by accident and thus didn't have the necessary intent for an assault (i.e., an intent to cause bodily harm). If the prosecution, however, can demonstrate that the defendant and victim had been arguing shortly before the alleged assault, that motive can serve as circumstantial evidence that a defendant really did mean to punch the victim. Alternatively, defendants can use the prosecution's lack of evidence of a motive as a "reasonable doubt" to avoid criminal liability.