For your first question... It depends on the context and meaning of "accidentally". If it implies carelessness, then 小心 is correct. Otherwise, 不意 to imply "unintentionally".
For the second one, 犯法 = broke the law; implying severity. Use 麻煩, 问题, 触犯 if you mean "a brush with the law".