Do these both have the same meaning?
- John carried out a crime.
- John committed a crime.
They both describe the same action, so you could use either. They have different nuances, both of which work against John's case:
Commit is in this sense almost always used of a misdeed. We do not "commit a brave rescue plan", we only commit crimes, murders, misdeeds, sins, misdemeanors, assaults, and so on. As such, it carries with it a suggestion of blame. This isn't the case with carry out which can apply to commendable deeds.
On the other hand, carry out carries with it a connotation of prior planning. We do not carry out impulsive thefts. We cannot be provoked into carrying out an assault.
Now, "malice aforethought" is often part of the legal distinction between murder and other forms of culpable homicide* like manslaughter, or between degrees of murder (just what distinctions are made vary with jurisdiction), and has a bearing on other crimes (including planning for some crimes being a crime in itself) or upon the sentence received. As such saying John carried out a crime, suggests he is more culpable than if he had committed it - because it was premeditated.
So, while as bare sentences the two are very close, and we would likely favour the first due to commit being more specifically related to crimes and other misdeeds, as part of a larger passage we might favour carry out to emphasise that he was completing a previously decided plan. This decision might be to underline a greater degree of culpability, or just because we had already described the plan, and were now moving on to talking about its execution.
*As distinct again from justifiable homicide such as in self-defence or war, which are not crimes.
Yes, but committed a crime would be more appropriate for writing. The phrasal verb carry out is quite informal, and should only be used in casual spoken contexts.
Although both phrases could be used interchangeably, you probably want to use "committed" because, when used correctly, "carried out" implies that the subject is doing the bidding of another.