Is a crime that is done in good intentions actually a crime?

I mean If someone mean's good by commiting a crime, should they still be punished for it?