If something happensby accident, it happens by chance. You can also say that it happensaccidentally.
I deleted the photo by accident.
I accidentally deleted the photo.
Two opposites ofby accidentaredeliberatelyoron purpose.
The group was deliberately targeting civilians.
You did it on purpose!
If something happensby mistake, it happens as a result of someone’s mistake.
I deleted the files by mistake.
You can also say that something was donein error.
Her name was passed to the police in error.