The preposition used with the word accident can be a touchy subject for some grammar purists. The traditional phrase is by accident. It means without intention or because of chance instead of effort or purpose.
On accident is a variation found almost exclusively inside the United States. It is grammatically on par with the phrase on purpose. One can either do something on purpose or on accident. Outside that particular comparison, this version is much less popular than by accident, with the latter being eight times more common. This is including instances outside of the United States as well.
This is one of the phrases that native US English speakers will go with what ‘sounds right’ or, more specifically, what they grew up hearing. For non-natives it is best to go with what is more popular, which is by accident.
Of course, one could always use the synonym accidentally.
Staff working at 14 Aldi stores reported the stashes of narcotics tucked in the produce deliveries from Colombia, which police believe ended up at the shops by accident. [The Guardian]
Gregory boasts top 10 talent and gives Dallas a potentially frightening trio of edge rushers with Greg Hardy and second-year pro Demarcus Lawrence, but Gregory’s slide wasn’t by accident. [CBS Sports]
“I sat down and wrote a real song, kind of on accident, drinking too much wine, trying to talk about my wife.” [Rolling Stone]
“A couple times, on accident, I’ll just get dressed for the day and I take one step out the door and I’m like, ‘Wait a minute. I can’t wear this.'” [Esquire]