As far as I can tell, they're the same thing.
A very subtle difference is that an 'accident' is unintentional, but a 'mistake' is not necessarily (it could also have been a poor, but intentional, decision).
Here, 'by mistake' clearly means 'accidentally'.
It's a bit more natural to say "It was an accident" in this case, in my opinion.